- Home /
Sprite rotation (z-axis) and translation (y) is not working
Hello everyone,
I have this game with asteroids, and I want my asteroids to rotate on the z-axis while going down with a y translation. Instead, the asteroids rotate slowly as they move in a circle towards the right.
Here is what's happening in an image:
Here is the code that gives me this result:
public GameObject asteroid;
public float speedZ;
public float speedDown;
void Update()
{
transform.Rotate(Vector3.forward * Time.deltaTime * speedZ);
transform.Translate(Vector3.down * Time.deltaTime * speedDown);
if (asteroid.transform.position.y < -5.5f)
{
Destroy(asteroid);
}
}
The value I am using at the moment for speedZ is 20, and for speedDown, 1,5.
The more the value of speedZ goes up, the more the circle in which the asteroid moves gets smaller. This can be seen in the following image where the asteroids have bunched up in a tight circle at a speedZ of 90:
Any help to solve this problem is greatly appreciated, Thank you in advance.
Answer by Timo326 · Feb 05, 2018 at 09:02 PM
Use Space.World in the translation as second parameter:
transform.Translate(Vector3.down * Time.deltaTime * speedDown, Space.World);
I feel so dumb, but thanks, you saved me plenty of hours of knocking my head on my desk!
Your answer
Follow this Question
Related Questions
How do I rotate player's camera to peak around objects. (first person shooter leaning) 1 Answer
How to rotate a gameObject towards a hit point along Z axis? 1 Answer
[2D] Player's arm following the mouse 1 Answer
Translate and rotate at the sametime problem 1 Answer
Move object forward relatively to itself 3 Answers