Need some help with a bullet script

  • I am using Javascript.
    I"m having an issue getting my projectile to shoot in the direction the player is currently facing. I can’t seem to get velocity to work on it at all. I’m currently using this in 2D using Constant force 2D in the bullet with a Rigidbody 2D. The script is located in a game object called SMG and it grabs a prefab (projectile / bullet), and clones the projectile, sets the value of thrust to the speed of the projectile, and the projectile travels in a certain direction the player was facing when it was fired until a set period of time and destroys.
#pragma strict

var muzzle : GameObject;
var thrust : float;
var projectile : Transform;
var Spawnpoint : Transform;

function shoot() {

var clone = Instantiate(projectile, Spawnpoint.position, projectile.rotation);
clone.GetComponent(Rigidbody2D).AddForce(Vector3.forward*thrust);
        muzzle.SetActive(true);
        yield WaitForSeconds(0.2);
        muzzle.SetActive(false);
}
function Update () {
    if (Input.GetMouseButtonDown(0)) {
        shoot();
    }
}

Try changing Vector3.forward to Vector3.right.

Forward is “into” the screen from the default 2D camera orientation.

Try also really wide ranges of values for thrust, like 1, 10, 100, 1000, etc