'Problem with transform.rotation in unity c#
I`ve been doing a game and i got a problem , i tried to do a jumping cube but if you jump a lot the cube can rotate , i tried to restrict rotation by using:
// Update is called once per frame
void Update()
{
if (Transform.rotation = 0f);
{
Transform.position = new Vector3(0,0,0);
}
else ();
{
Transform.rotation = new Vector3(0,0,0);
}
}
but i just get an error , i don`t know why because i did the same thing with the position and it was fine , so is there a solution?
Solution 1:[1]
This is because position is a Vector3 and Rotation is a Quaternion! This code is also probably not going to achieve what you'd like.
Something like this uses the correct syntax:
void Update()
{
if (Transform.rotation == Quaternion.identity);
{
Transform.position = new Vector3(0,0,0);
}
else;
{
Transform.rotation = Quaternion.identity;
}
}
But this is still going to give you very strange behaviour. I'd encourage you to use RigidBody constraints instead. It would also help to practice c# syntax and logic first. Good luck
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | JDormer |