Given: A rigidbody with mass m, drag d, uses gravity g, and has a certain velocity v at time t
How to estimate the position where this rigidbody will be at time t + dt under the assumption it will not collide with anything, and that m, d, and g are constant?
Details:
I am trying to implement helicopter controls for an arcade game. The copter should hold a certain distance above the ground and automatically adjust its boost to get to this distance depending on how the ground/terrain below the copter changes. I’ve tried to implement hovercraft-style which basically worked, but feels unnatural for a helicopter.
Now, I am trying a different approach: Apply acceleration forces to reach the specific distance to the ground (ForceMode.Acceleration, which ignores the mass of the copter). If the copter, for instance, is below the target-distance, i would apply an upwards acceleration force in every FixedUpdate. I would stop applying the upwards acceleration if could calculate that based on the current velocity, the estimated position of the copter will reach the target-distance to the ground.
In this case forces are not needed; rather than constantly “fighting” the downward pull of gravity, you could instead have a capsule collider stood vertically which contains your chopper at the top, and have it simply slide along your terrain, making sure that you constrain the collider so it doesn’t start rotating. The height of your capsule collider then directly relates to the height that your chopper flies at - that then reduces changing heights to simply changing the height of your capsule collider (which can be animated too).
This setup will result in the chopper “instantly” responding to the terrain height - i.e. as you start flying over a hill, the chopper will immediately move upwards as the bottom of the capsule collider is pushing against your terrain. If you want to make it appear to have a delay, i.e. as the chopper reaches the top of the hill it starts moving upwards, simply offset the capsule collider from the visual chopper. Imagine this as the chopper dragging the collider behind it, being naturally pushed upwards when the collider hits higher ground.
(Collider wouldn’t be visible in the actual game of course! It’s essentially just a child of the chopper, and this setup works the same in 2D or 3D)