Flying physics: acceleration while diving/ascending

This topic is 2500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi,

I've got a small prototype involving a character that flies across a 2d landscape. The character in question isn't a plane and I'm not requiring any advanced physics such as lift, gravity etc.

The character in question currently moves by having a set speed and between frames, I calculate the angle I need to turn from the default and set the character's heading appropriately by rotating the movement vector. While this works, the character has a very uniform movement style and speed that isn't very interesting.

Due to the way I've designed it so far, I'm having trouble creating a system where the character accelerates/decelerates in a fluid way that isn't either horrible to look at or a nightmare to code and I was wondering if anyone might suggest a nice method/way of thinking about the problem that might work?

Please let me know if I need to clarify anything.

Share on other sites
So I take it no gravity means top-down? One clarification: how is the angle you need to turn to calculated? Does the player press left or right to rotate continuously, or does he press a direction to instantly face that direction - or is it something different?

Share on other sites

So I take it no gravity means top-down? One clarification: how is the angle you need to turn to calculated? Does the player press left or right to rotate continuously, or does he press a direction to instantly face that direction - or is it something different?

Sorry, I'll try and clarify:

Its actually side-on, the character by default hovers at a certain height and when a button is pressed, they dive down. When the button is released, the character returns to their original height.

The angle is calculated using this code:

//We need to calculate absolute angles between character current heading and upper limit/ground //get vector to upper y zVec2f vecToUpper, vecToLower; vecToUpper.x = getPosition().x + 5.0f; vecToUpper.y = baseline_y_upper; vecToUpper = vecToUpper - getPosition(); vecToUpper.normalise(); //angle from straight-up to vector pointing towards upper limit float UpperVecAng = vecToUpper.getAngle(); //get vector to lower y vecToLower.x = getPosition().x + 5.0f; vecToLower.y = baseline_y_lower; vecToLower = vecToLower - getPosition(); vecToLower.normalise(); //angle from straight-up to vector pointing towards ground float LowerVecAng = vecToLower.getAngle(); zVec2f heading = moveDir; heading.normalise(); float headingAng = heading.getAngle(); //calculate difference in current heading and upper/lower trajectories float UpperAngDiff = UpperVecAng - headingAng; float LowerAngDiff = LowerVecAng - headingAng; 

Once I have the difference between the character heading and the upper/lower limit, I reset the character heading back to default, calculate a turn based on a turning speed value and set the new angle to that.

The only input the player makes is pressing a button to make the character start diving, if they press nothing, the character just flies forwards and bobs at the maximum height (or turns upwards and flies towards the max height if they are below it).

Share on other sites
how do you want it to move?

My first thought is to separate y and x-movement. x-movement could be constant or slightly accelerating (endless runner style)
when you press, you start to accelerate the y-speed, making it "go down" faster and faster while holding the button.
Maybe you want a "lower limit" where it will start decellerating instead so it can't go below a fixed height too.
Releasing the button to reverse it. (start accelerating upward until its "close enough" to the top, then decellerate so it levels out at the max height)

This would give it a bit "sinus"-like movement.

Share on other sites

how do you want it to move?

My first thought is to separate y and x-movement. x-movement could be constant or slightly accelerating (endless runner style)
when you press, you start to accelerate the y-speed, making it "go down" faster and faster while holding the button.
Maybe you want a "lower limit" where it will start decellerating instead so it can't go below a fixed height too.
Releasing the button to reverse it. (start accelerating upward until its "close enough" to the top, then decellerate so it levels out at the max height)

This would give it a bit "sinus"-like movement.

This is actually what i had in mind, my worry was that the x-movement would remain constant and it would simply replicate my current problem, only limiting it to x-axis movement. I suppose I could try accelerating x-movement by using y-speed as some kind of input but I'm not entirely sure how this would work.

Share on other sites
In a normal sinus-wave motion, the x-speed is constant.

In any case, separating the two, would make it easier to tweak until it behaves like you want.

If you implement it with constant x first, then you can simply add a factor you multiply the y-acceleration with, before applying it to the x-speed.
Then x-acceleration would depend on y-acceleration in a tweakable way.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• Forum Statistics

• Total Topics
633704
• Total Posts
3013460
×

Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!