last day (16 days later) » 

17:24
0
Q: How could I move an object, while respecting the gravity and other related physics in Unity?

qqqqqqqHow could I move an object, while respecting the gravity and other related physics in Unity? I tried using the following approach: void FixedUpdate() { rigidBodyToMove.velocity = velocity; } The problem with that approach is, for example, when the object falls from a height t...

@Philipp, I want my character to run with a constant speed all the time, unless there is a wind, drag of surface changes or anything else physics related happens.
I think your actual problem could be that you are having various physical forces which act on your object (gravity, wind, collisions...) but then want your movement to not act like a physical force but instead act like a constant velocity layered on top of all the physical movement. Does that sound right?
@Philipp, you are right. That is what I want. So, if there are no physical forces, I want to run with the same speed.
@DMGregory, sounds like it is what I was looking for. I will try to check it out during the next 2 days and will let you know if it worked for me. Thank you.
@DMGregory, it seems that the linked questions is not what I am looking for. E.g. there is a wind which blows in characters back from right to left. And here a user which presses a button for a character to go from right to left. In your linked questions the character will move with the same speed all the time irrespectively of the wind presence, while I want the character to move faster when there is a wind and move as usual when there is no wind.
17:24
That's easy to achieve. Add the wind to the target velocity.
That is a bad idea I think. Because it looks like a technical debt putting all the physics features not into the physics engine, but in the entity which should be affected by the feature. Except character I have enemies, grass, etc. Should I add wind to all of these as well? I will have other physics features, should I put them all on my character as well? I think, no. :)
@DMGregory, I am not quite sure yet (still researching at experimenting), but I think I found a solution. This thread made me think that the Rigidbody.MovePosition method was created specifically for my use case. :)
MovePosition moves to exactly the position you tell it. That does not sound like the use case you've described above, unless you plan on summing the effects of gravity, wind, etc together when computing that destination position to pass to MovePosition.
@DMGregory, yes you are right. I just tried it and it roughly speaking has the same effect as setting the rigidBodyToMove.velocity does. So, even this does not work. I wish there would be a way to put my addendum into the unity physics computations somehow. :(
@DMGregory, how did not Unity anticipate something like this. This problem makes me even doubt if I want to continue using Unity. :(
This does not have anything to do with Unity anticipating or not anticipating your unique preference for how you'd like it to work. Real world physics does not contain separate channels for impulses from different sources: they all pool into the same momentum. And so the physics engines that Unity uses, PhysX and Box2D, along with every other physics engine I've ever seen, Bullet, Havok, etc, imitate real physics. And hundreds of successful games have been built on that foundation, so this is not an obstacle that needs to block you. You just need to be open to thinking of different approaches.
Put another way, if you move an object in a way that can occur in real physics - like with a thruster that exerts a reaction force, or a limb or wheel pushing against the collider below, then all the various physics effects layer together naturally, out of the box. You don't need to do anything special.
But because you deliberately want to break physics here, by making an object that moves at a constant velocity, relative to a fictional version of itself that's moving inertially, then it's up to you to craft that special behaviour. You've stepped outside the realm of real-world physics the engine simulates, but it gives you all the tools you need to build non-physical behaviour too. You just have to work for it.
For instance, you could create an inertial frame component that accumulates accelerations from gravity/etc, and the motion of the medium you're in (like wind/conveyors/moving platforms/etc). Then your movement component could apply its desired velocity relative to that medium.

  last day (16 days later) »