- Home /
Sprite is a little of when rotating
Hi there!
As the title says, my sprite is a tiny bit of when I want to rotate it. It is supposed to choose one of the following rotation values at random (btw is there a better way to do this?):
// just an example function
void CreateSprite() {
Vector2 tilePosition = this.transform.position;
Quaternion tileRotation = this.transform.rotation;
int[] possibleRotations = new int[] { 0, 90, 180, 270 };
tileRotation.z = possibleRotations[Random.Range(0, 4)];
Instantiate(tilePrefab, tilePosition, tileRotation);
}
int[] possibleRotations = new int[] { 0, 90, 180, 270 };
But when I try this, the sprites actual rotation value is a little bit different from those in the list. I debug logged the rotation and it appears to be set correctly, however ingame its all wrong. As an example:
Randomly chosen rotation: 90 degrees
Rotation displayed in debug log: 90 degrees
Actual rotation ingame: 89.576 degrees
Answer by s_awali · Dec 05, 2018 at 03:30 PM
Quaternion are NOT Vectors -> if you want to set the angle around the Z axis, then use eulerAngles
.
Example :
tileRotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, possibleRotations[Random.Range(0, 4)]);
Your answer
Follow this Question
Related Questions
Sprite rotation with animation (2d project) 0 Answers
2D sprite animation issue 0 Answers
2D spaceship rotation 0 Answers
Joystick 2D Sprite Rotation and Movement 0 Answers