- Home /
Question by
colmassakian · Oct 12, 2015 at 12:57 PM ·
movementrigidbody2daddforce
Rigidbody2D.AddForce is not moving the object
I'm trying to make a projectile move using its Rigidbody. I've looked at quite a few responses on this forum, but no matter what I try, the projectile does not move. I've tried Vector3.forward force and transfrom.right force, neither one works. Also, I've tried setting force to as high as 1000, again, with no luck. Any help is appreciated.
using UnityEngine; using System.Collections;
public class Fire : MonoBehaviour {
public float force;
public GameObject projectile;
public GameObject RocketLauncher;
//Use this for initialization
void Start () {
projectile.transform.rotation = new Quaternion(RocketLauncher.transform.rotation.x,RocketLauncher.transform.rotation.y,RocketLauncher.transform.rotation.z-90,RocketLauncher.transform.rotation.w);
}
//Update is called once per frame
void Update () {
if (Input.GetKeyDown("space")) {
projectile.GetComponent<Rigidbody2D>().AddForce(transform.right * force);
}
}
}
Comment
It isn't, the problem was because this script is on my weapon, not my projectile, so the transform.right references the wrong object.