# Continuously Rotating object on Y axis and move it on x axis continuosly

i m using three rocks for my game all three moves in the direction of x-axis, i’ done with moving the rock on the x axis but i also want to rotate them on Y axis, so the rocks move on x axis with some spin, sorry my English is too bad hope you can understand, Thank you in Advance…

here’s my script for moving the objects.

public class object1 : MonoBehaviour {
[SerializeField] private float objectSpeed = 1;
[SerializeField] private float resetPosition = -35.5f;
[SerializeField] private float startPosition = 66.9f;

``````// Use this for initialization
void Start () {

}

// Update is called once per frame
protected virtual void Update () {
if (!GameManager.instance.GameOver) {
transform.Translate (Vector3.left * (objectSpeed * Time.deltaTime));

if (transform.localPosition.x <= resetPosition) {
Vector3 newpos = new Vector3 (startPosition, transform.position.y, transform.position.z);
transform.position = newpos;
}
}

}
``````

}

Keep it simple @SallarQ

``````void Update(){
transform.rotation += Vector3.up * time.deltatime * speed;
}
``````

Dont forget to set a speed. Good luck

you can use :

``````Vector3 rotationSpeed = new Vector3 (yourRotationSpeedX, yourRotationSpeedY, rotationSpeedZ);
transform.Rotate (rotationSpeed);
``````

or

``````Vector3 rotationValue = new Vector3 (rotationValueX, rotationValueY, rotationValueZ);
transform.rotation = Quaternion.Euler (rotationValue);
``````

You can use Coroutine

``````private IEnumerator rotate(){

float rotation = transform.rotation.y;

while (true) {
rotation += 50;
transform.rotation = Quaternion.Euler(new Vector3(0, rotation, 0)); // rotate on y axis
yield return new WaitForSeconds(0.1f);
}

}

StartCoroutine(rotate());
``````