- Home /
Having trouble turning off gravity through script
I'm creating a script that launches a missile from a helicopter, and I want the missile to fall a bit and then launch. I have useGravity unchecked in inspector.
When I launch the missile, it drops (because the script sets useGravity to true), and then starts moving forward after .5 seconds (using constantForce.force and yield WaitForSeconds), but keeps falling even though I set useGravity to false after yield WaitForSeconds(0.5).
Could it be the yield that keeps it from finishing the execution and turning off gravity?
**Note: When I launch the missile, in inspector, I see Use Gravity quickly check its box then uncheck it.
Answer by AnXgotta · Aug 12, 2012 at 05:03 AM
You probably need to set the missile y velocity to zero after you turn gravity off to stop the motion in that direction.
Yep. Then it will appear to sit still until that force begins to move it forward.
Edit: Removed unnecessary content.
Edit: If this is the correct answer please mark it as such :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613075530im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to do this? 2 Answers
Apply low gravity only for specific object. 1 Answer
Jetpack flame only in the air 1 Answer
Spawn System Troubles 0 Answers
Low gravity on trigger. 2 Answers