Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (686) Games in Android Showcase (198) games submitted by our members Games in WIP (758) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Realistic 2D helicopter sidescroller movement tips  (Read 4561 times) 0 Members and 1 Guest are viewing this topic.
Wordsw0rth

Junior Newbie

 « Posted 2013-11-06 20:09:15 »

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

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

Best regards!
Danny02
 « Reply #1 - Posted 2013-11-06 21:28:14 »

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.
Jimmt
« League of Dukes »

JGO Kernel

Medals: 167
Projects: 5
Exp: 6 years

 « Reply #2 - Posted 2013-11-07 00:39:56 »

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.
TimV

Junior Newbie

 « Reply #3 - Posted 2013-12-24 10:23:26 »

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

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.
Oskuro

JGO Knight

Medals: 59
Exp: 6 years

Coding in Style

 « Reply #4 - Posted 2013-12-24 17:44:25 »

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".

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.

Genius Coder

Junior Devvie

Medals: 1
Exp: 4 years

 « Reply #5 - Posted 2014-01-21 22:17:47 »

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.

I love making games...
kramin42
 « Reply #6 - Posted 2014-01-22 06:08:46 »

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 ).

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.

"All science is either physics or stamp collecting." - Ernest Rutherford.
CodeGolf4k
M4nkala
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 roseslayer (490 views) 2016-08-06 11:43:29 roseslayer (448 views) 2016-08-06 09:43:11 xTheGamerCodes (522 views) 2016-08-04 15:40:59 xTheGamerCodes (515 views) 2016-08-04 15:40:24 orrenravid (863 views) 2016-07-16 03:57:23 theagentd (942 views) 2016-07-11 14:28:54 Hydroque (1036 views) 2016-07-06 05:56:57 Hydroque (1023 views) 2016-07-03 08:52:54 GrandCastle (839 views) 2016-07-01 09:13:47 GrandCastle (640 views) 2016-07-01 09:09:45
 Archive 46x Spasi 24x Ecumene 23x theagentd 23x orange451 15x DarkCart 15x h.pernpeintner 14x gouessej 14x EgonOlsen 13x ags1 12x admin 10x Riven 10x philjord 9x TheMeatMan 8x Brynn 8x Slyth2727 7x
 Rendering resourcesby Roquen2016-08-08 05:55:21Rendering resourcesby Roquen2016-08-08 05:52:42Rendering resourcesby Roquen2016-08-08 05:50:38Rendering resourcesby Roquen2016-08-08 05:49:53Rendering resourcesby Roquen2016-08-08 05:32:39Making a Dynamic Plugin Systemby Hydroque2016-06-25 00:13:25Java Data structures2016-06-13 21:22:09Java Data structures2016-06-13 21:20:42
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org