Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Realistic 2D helicopter sidescroller movement tips  (Read 2701 times)
0 Members and 1 Guest are viewing this topic.
Offline 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 Sad

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  Roll Eyes

Best regards!
Offline 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.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 131
Projects: 4
Exp: 3 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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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  Grin

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

JGO Knight


Medals: 39
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".

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.

Offline Genius Coder

Junior Member


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

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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (22 views)
2014-09-19 03:14:18

Dwinin (35 views)
2014-09-12 09:08:26

Norakomi (62 views)
2014-09-10 13:57:51

TehJavaDev (88 views)
2014-09-10 06:39:09

Tekkerue (44 views)
2014-09-09 02:24:56

mitcheeb (65 views)
2014-09-08 06:06:29

BurntPizza (47 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (40 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!