Reputation: 72
I am trying to rotate an object within certain boundaries, but the object does not rotate.
public class shincon : MonoBehaviour
{
Rigidbody rb2;
float shinspeed = 10;
// Use this for initialization
void Start()
{
rb2 = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
float Posax = Input.GetAxis("leftshin");
if (Posax != 0)
{
Vector3 move = new Vector3(shinspeed * Posax * Time.deltaTime, 0, 0);
transform.rotation = Quaternion.identity;
Vector3 euler = transform.rotation.eulerAngles;
float clampx = Mathf.Clamp(move.x + euler.x, 0, 160);
Vector3 ready = new Vector3(clampx - euler.x, 0, 0);
Quaternion rmove = Quaternion.Euler(ready);
rb2.MoveRotation(rb2.rotation * rmove);
}
}
}
No syntax errors, but it will not rotate.
Upvotes: 0
Views: 1149
Reputation: 90580
After the line
transform.rotation = Quaternion.identity;
The next
Vector3 euler = transform.rotation.eulerAngles;
will always return 0,0,0
.
And further
Quaternion rmove = Quaternion.Euler(ready);
Results in Quaternion.Identity
so finally
rb2.MoveRotation(rb2.rotation * rmove);
always results in Quaternion.Identity
as well so the object will never be rotated.
Remove the line
transform.rotation = Quaternion.identity;
Upvotes: 1