Object spinning around it's own axis whilst travelling in a straight line

I’ve been using the following script to randomly rotate an object on instantiation and then have it travel in a straight line:

using System.Collections;

public class shrapnel : MonoBehaviour {

public float speed = 10;
Vector3 randomDirection;
Vector3 position;


// Use this for initialization
void Start () {
	
	//Setting the angle and rotating the shrapnel, ready to move
	float randomAngle = Random.Range (-35, 35);
	transform.Rotate(0f, 0f, randomAngle);	
		
}

// Update is called once per frame
void Update () {
	
	//Shrapnel travels in direction of local rotation, in opposite direction to local up
	transform.Translate((transform.up * -1) * speed * Time.deltaTime, Space.Self);
	
	//Destroy when off the screen
	if (transform.position.y < 0){
		Destroy(this.gameObject);			
	}		
	if (transform.position.x < 0 || transform.position.x > Screen.width)
		Destroy(this.gameObject);
	
	//Apply spinning motion

	

}

}

It’s a 2D game.

But since I’m using the local direction to move, if I use transform.Rotate to make the shrapnel spin on its axis whilst it goes in a straight line, it changes the trajectory of the object.

I’ve tried using rigidbody.AddTorque since I thought the torque axes would be separate to rotation axes, but it’s having no effect (a rigidbody component HAS been attached).

Does anyone have any ideas what I could do here?

Many thanks in advance.

It’s almost incredibly easy to do this - you’ll be sick.

Say your object is called SHIP, ok.

Make a new object … a wrapper object. So do this, make a new empty game object, called SHIPWRAPPER.

Put it in exactly the position of the ship. Now put the ship INSIDE the wrapper.

Now, just have SHIP itself spin, tumble or do anything you want.

Treat the actual WRAPPER object, as “the ship itself”. So for example, say you have a script “make the ship travel to Canada” … in fact you’d attach that to the WRAPPER, rather than the ship itself. And so on.

It’s just that easy - the incredible beauty of the abstraction layer of “transforms” with quats in game engines. Hope it helps!

BTW the simplest way to make the SHIP spin (tumble, whatever) within the SHIPWRAPPER,

just use the (“traditional”) animation system in unity. don’t even bother trying to write a script.

(BTW for anyone reading who is brandnew to unity, take the opportunity to learn how to “spin” something using the animation screen … it’s super-easy - just click Apple-6, click record, click to add a curve on Z rotation and add a key point at zero seconds and a key point at 5 seconds, then set the two key points to 0 and 360 on the z rotation, and set to wrap down the bottom, that’s it.)