- Home /
Add/remove Gravity with code
HI all , I have an plane that work with rigidbody.velocity(forward) and I write this code for increase gravity and decrease height when speed down but when speed is normal can't see any change for plane and when slow down to min speed again no change and after a short time Suddenly plane fall!! How can I write code that control speed and down force for plane?
( Speed down and come down slowly and smoothly )
//Control Gravity and height with Speed
Gravity = -1 / Speed * 110 ;
rigidbody.velocity.y += Gravity;
Answer by sparkzbarca · Mar 11, 2013 at 11:26 AM
it doesn't matter what you can "See" check the numbers in the editor.
bear in mind your formula for gravity is NOT
-1/ (speed * 110)
its
(-1/speed) * 110
I only mention it cause the bottom line is pointlessly complicated
you could simply write that
gravity = -110/speed
but I think you want the top line in which case you need to remember your order of operations.
thanks , I forget that * is first and / is next . from other side in mathematics for example when :"a = 1/b" and "b" is very very small number and close (tend) to zero the "a" get infinite and because of that when speed get close to zero and stopping the gravity get very big and near to infinite and cause falling down.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
[HELP] Rotate Bullet Script 0 Answers
Detecting sudden changes in velocity? 1 Answer
Planet gravity help need guidance no code 1 Answer
What is the velocity of Gravity? 1 Answer