- Home /
Glider physics with AddForce 2D
Hello! I am making a game where the player is using a "glider" in 2D space to fly, i would like to achieve the effect of "gaining speed" when rotating downwards, and then when rotating upwards you would reach a max speed and then start tilting down again, and loose speed over time so that you would eventually stop completely.
Here is a picture to make it more clear:
I dont know alot about coding but this is what i tried so far:
public float flightSpeed = 25.0f;
void FixedUpdate () {
rigidbody.AddForce(Vector3.forward * flightSpeed);
}
I also use a script to rotate the character, and it does go in the right direction its facing, but it keeps going forever, and doesn't loose speed when going upwards.
(The game is in 2d space but the character is a 3d model)
Any tips on how i could achieve this effect? :)
Answer by hexagonius · Dec 09, 2014 at 09:01 PM
Check out the Vector3.Dot function. if you use it with your Vector3.forward and Vector3.up, you should get 0 when horizontal, negative values when the nose is pointing down and positive ones when pointing up. Subtract a multiple of that value from the applied force (or add when using Vector3.down) and you should get something like you want.
Your answer
Follow this Question
Related Questions
Calculate forces required to rotate around an arbitrary point regardless of center of mass position 1 Answer
Lerp to target position in X amount of time 2 Answers
Trouble in freezing movement in z axis 1 Answer
Rigidbody2D.mass editable during runtime? 0 Answers
AddForce to opposite direction 2 Answers