Projectile that moves forward and rotates

I did this script, but the shot gets in a loop in the air, rather than keep moving straight forward. I want the shot to go forward and at the same time spin in the air.

How do I this?

Current Script:

transform.Translate(Vector2.right * velTiro2 * Time.deltaTime);
transform.Rotate(Vector3.forward * 300f * Time.deltaTime);

The first line is for the projectile to go forward.
The second line is for it to rotate around the z-axis itself.

When I remove the second line, the projectile moves forward normal.
But with this line ‘transform.Rotate’, the projectile do a loop.

It’s pretty simple if you make a parent object that has the physics/logic for the “go straight” portion of the equation, and the model child object have the physics/logic for the “spin in place” portion. That way it can spin independently of the object’s forward movement.

As to how to spin it without messing up the trajectory as a single object, transform.Translate is relative to the current orientation by default, so you’d need to specify transform.Translate(direction * speed, Space.World)… I think.

1 Like

Thank you Lysander. In this case, can I create an empty object like parent that moves forward and, inside it, create a child object that will be the rotating shuriken?

Yep, that’s the idea.

1 Like

I did it this way, I created a RotateProjectile script and put the code:

public float rotationSpeed;

    void Start () {

    }
   
    void Update () {
        transform.Rotate(Vector3.forward * rotationSpeed * Time.deltaTime);
    }

And in the parent, the code:

public float projSpeed;

void Update() {
        transform.Translate(Vector2.right * projSpeed * Time.deltaTime);
}

It works fine, just the way I want.!!
Thank you for the tips!!