Car z.max angle ?

Updated on May 22, 2017 in Answers
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
6 on May 20, 2017


I want to make an angle for my car that can not cross it.
I’m talking here about the Z angle only.

 public float maxAngle; // 30 max angle
 // Update is called once per frame
 void Update () {
 maxAngel = transform.eulerAngles.z;
 if (maxAngel >+ 30) {
 transform.eulerAngles.z = 30f;
 }
 }
 

I used here eulerAngles but it doesn’t work. is there something else ?

  • Liked by
Reply
5 on May 20, 2017
transform.eulerAngles.z = Mathf.Clamp (transform.eulerAngles.z, -30, 30);
on May 20, 2017

One line only !! I thought this will need more than 20 lines.
OK. It not work. it gives me error.

Cannot modify the return value of 'UnityEngine.Transform.eulerAngles' because it is not a variable.

How to fix this ?

Devoted
on May 20, 2017
private Vector3 tempAngle = Vector3.zero;
tempAngle = transform.eulerAngles;
tempAngle = Mathf.Clamp (tempAngle.z, -30, 30);
transform.eulerAngles = tempAngles;

Try this, I don’t know if it will work or not.

on May 21, 2017

I got error form the third line.

Cannot implicitly convert type 'float' to 'UnityEngine.Vector3.

Thank you for your try.

Devoted
on May 21, 2017

Yeah, try this:

tempAngle.z = Mathf.Clamp (tempAngle.z, -30, 30);
on May 22, 2017

Thank you so much.

Show more replies
  • Liked by
Reply
Cancel