rotation couldn't able to understand

am doing a space shooter game, where i have created a comet which has to move backward and rotate in x direction. i have done the translation,but the rotation its not working the way i thought. when the comet object is static the script rotates the object around its axis, but when it is moving the object rotates in a circular path.the script is below. can some one help in making understand how rotation works.

``````using UnityEngine;
using System.Collections;

public class comet : MonoBehaviour {

public float cometSpeed = 0.5f;
public GameObject enemy;
public float cometRotationSpeed = 3;

private float xPosition,yPosition,zPosition;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

transform.Translate(Vector3.back * cometSpeed * Time.deltaTime);
transform.rotation = Quaternion.Euler(new Vector3(cometRotationSpeed * Time.time,0,0));

if(transform.position.z <= -17.60204f)
{
cometPositionAndSpeed();
}
}

void cometPositionAndSpeed()
{
xPosition = Random.Range(-0.3894582f, -5.079246f);
yPosition = 0.5529938f;
zPosition = -0.095191f;

transform.position = new Vector3(xPosition,yPosition,zPosition);
}
}
``````

You’re doing the rotations correctly, but the translation is in object/local space (Self).

This means that when you start rotating the comet the path it will follow will rotate along with it. A solution is to set the second parameter of the Translate() method to Space.World.

See line 20 in the code.

``````using UnityEngine;
using System.Collections;

public class comet: MonoBehaviour {

public float cometSpeed = 0.5f;
public GameObject enemy;
public float cometRotationSpeed = 3;

private float xPosition,yPosition,zPosition;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

transform.Translate(Vector3.back * cometSpeed * Time.deltaTime, Space.World);
transform.rotation = Quaternion.Euler(new Vector3(cometRotationSpeed * Time.time,0,0));

if(transform.position.z <= -17.60204f)
{
cometPositionAndSpeed();
}
}

void cometPositionAndSpeed()
{
xPosition = Random.Range(-0.3894582f, -5.079246f);
yPosition = 0.5529938f;
zPosition = -0.095191f;

transform.position = new Vector3(xPosition,yPosition,zPosition);
}
}
``````

Use transform.localRotation or transform.eulerAngles