- Home /
 
rigidbody2D.AddForce() not working
using UnityEngine; using System.Collections;
public class RocketScript : MonoBehaviour { public Vector2 speed = new Vector2(0, 20);
 public Vector2 downspeed = new Vector2(0, -20);
 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {
     
     
     
     
     
 }
 void FixedUpdate () {
     if (Input.GetKeyDown (KeyCode.DownArrow))
                     rigidbody2D.AddForce (downspeed);
     if (Input.GetKeyDown (KeyCode.UpArrow))
         
                     rigidbody2D.AddForce (speed);
     }        
         
 
 
               } is my script but when i playtest it doesnt work-the sprite doesnt move (the rocket). Im not all that clear on how to use the addforce function and ive even read the docs but still not grasped it, so if anyone could help it would be very much appreciated.
Check the value of 'downspeed' in the Inspector. The assignment you make will only be used when the script is attached.
Answer by LeonardNS · Aug 08, 2014 at 06:18 PM
I see you are using the "Input.GetKeyDown" instead of the "Input.GetKey". When you use the KeyDown this only happens once when you first press the key, with GetKey it happens as long as you hold the key down. Another problem is that only 20 and -20 force is applied. That is not very much. I think you should scale thoose numbers up a bit to maybe 40 and -40. And if you really meant to write "Input.GetKeyDown" maybe 200 and -200.
Your answer
 
             Follow this Question
Related Questions
Rigidbody2D AddForce only working with large numbers 2 Answers
Jump problem 1 Answer
Unity 2D Physics .AddForce 1 Answer
Can someone help me with this Rigidbody2D bug? 1 Answer
Character instantly jumps instead of smoothly gaining altitude 3 Answers