Realistic 2D helicopter sidescroller movement tips

Hi!
I’m making a 2D helicopter sidescroller (original, I know!) where the helicopter is fixated in the middle of the screen and makes his way past obstacles. I’m having trubble finding a good solution for “realistic” movement speeds with gravity affecting etc.

I’ve gotten a bit into the game now and since I from the start really wanted to get coding and didn’t know the math behind the “realistic” movements I used fixated movements instead (as in i move up, down, left or right untill i let go then dont move anymore).

I want my helicopter to be affected by gravity the whole time, and I can’t really find any good examples for this anywhere :frowning:

Up-key = makes the helicopter accelerate up untill you hit the max speed.
Down-key = makes the helicopter accelerate (faster acceleration then if you just let the up-key go) downwards untill you reach max fall speed.
Left-key = makes the helicopter go left untill you hit max speed but still with gravity “pulling” it down
Right-key = same as left but to the right.

I tried searching both here and all over but it seem hopeless.
Does anyone know any good examples that I can look at or maybe someone can try to explain it to me here? <3 ::slight_smile:

Best regards!

Let’s think this through.
You want to do a simplified simulation. For simple movement you need acceleration, velocity and position for both in the horizontal and vertical direction. Remember that the two directions are totally independent of each other.

These three attributes build a hierarchy, the acceleration manipulates the velocity and the velocity the position. In your simple simulation you will only touch the acceleration and the other two are just some variables of your helicopter.

So for the vertical movement you define three states, a lot of up force(UP key), a little up force (no key) and no up force(DOWN key). Depending on the state you assign an vertical acceleration (i.e. 10, 6, 0) and subtract the gravity(a negative acceleration).
For the horizontal movement things are simpler you have only an acceleration in a direction or none.

After that you can calculate the next value for the velocities and positions.

When you want to limit the max speed of your helicopter, you can of course just cap the velocity, but there is a even nicer(more correct) way. You can simulate things like air resistance easily by just subtracting from the current acceleration some value which is dependent of the current velocity.

I’d do what Danny02 suggested, and then add some forwards/backwards rotation when moving in those directions, for a easily made but also more realistic simulation.

By lifting the wind underneath the blades of a helicopter a helicopter defies gravity, so flying is the absent of gravity ;D

distance flown : speed * time.

calculate this over the x, y and z axis and you have your movement in those directions.
Now you have only 2 axis you want to fly on.

Use triangle calculations to find the increasment of the axis :

lets say up and down is the Z-axis.
front to back is the X-axis

xincrease = Math.cos( angle of flight) * distance
zincrease = Math.sin( angle of flight) * distance

remember to recalculate to radians, cause MAth class uses radiants and no degrees

Now for drag you can substract that from the distance.
For windverlocity and direction, you can do the same calculations and subtract them from your movement.

if you mean that you must keep pressing a button up to stay up, you can use curve to acceleration for falling, at first go slow and speed up the fall.
static energy becomes kinetic energy (or something like that)
acceleration over the Z-axis : zdownfall = zdownfall + increasment
Then when you press the up key : zdownfall = 0

For 3 dimensions movement I have problems too, so dont ask me.

Another way to see a helicopter is as a rocket pointing upwards that is, when hovering, generating enough thrust to stay at a fixed distance from the ground.

In fact, helicopters move around by angling their propellers so the vertical thrust gives them a push in the desired direction (with the associated loss of lift).

You could model the helicopter similar to the classical lunar lander. It has a vertical thrust that directly opposses the vertical pull of gravity. When the player decides to move around (left right, I’m assuming a 2d game here), the copter tilts, so the vertical component of the thrust diminishes, yet the horizontal component increases, generating lateral motion, but causing a drop in height.

The up/down keys would increase/decrease that vertical thrust vector then.

For simplicity’s sake, I’d make the control scheme so that, when the player is doing nothing, the helicopter attempts to move back to the hover position, that is, thrust vector pointing straight down, and thrust power being exactly enough to keep level. So all a player needs to do to stabilize is let go of the controls.

A lot of the control would then be about tilting the helicopter and compensating with thrust (hitting the up key) to keep level and move fast, or tilting for a while to gain horizontal momentum, and then letting go so the helicopter “slides”.

It’s all about inertia.

As for how this would work in 3d, go ahead and install the following: Battlefield 1942 and the Desert Combat mod, then jump into a chopper… And be prepared to crash. Love those choppers as I do, it is hard to master, but it works exactly as I’ve described (except that there is no “auto hover”, you need to keep giving the copter bursts of “gas” to keep it aloft, something I wouldn’t recommend in a control scheme).

Edit: Another option is to have two thrust components, one for vertical and one for horizontal movement.

The way that I have used in my games is to first create the helicopter class that has both an x and y vakue . a velx and vely integer is added in the update method and is currently set to 0 however pressing a key will change the velocity and releasing a key will set not velocity integers to 0.

A good way to do this is just to have the vely set to 1 so that the helicopters x increases by 1 pixel per update because all positions are correspondent to the top left corner of the widnow make sure this happens when the up key is not pressed.

Here’s a basic little simulation I made: http://kramin42.github.io/helicopter.htm
Click inside the box to give it focus and the arrow keys control it.

Is this kind of what you want? The throttle (lower left) is modelled as a damped spring and the helicopter accelerates according to the throttle, with another damping factor.

The result might be a little unresponsive, but I’d say that’s probably realistic (I don’t really know because I’ve never flown a helicopter :P).

The source code of the webpage has the code in it (it’s made with processing.js) but it’s rather illegible. I can explain it better if you want.