- Home /
Restricting GameObject Rotation
Im having a bit of a problem restricting the rotation of my character i only want the character to have a rotation of 0,90,180 and -90 my script looks like this
     var Distance = Vector3.Distance(target.position,transform.position);
 var Angle = transform.rotation.eulerAngles.y;
 
 if(Angle > Rotation90){
 Angle = Rotation90;
 }
 
 else if(Angle < RotationMinus90){
 Angle = RotationMinus90;
 
 }
 else if(Angle > Rotation180){
 Angle = Rotation180;
 
 }
 else if(Angle > Rotation00){
 Angle = Rotation00;
 
 }
 
 
 
 if(ZombieMove)
 
 {
 Debug.Log(Angle);
 //Debug.Log(Distance);
 transform.rotation.eulerAngles = new Vector3( 0, Angle, 0 );
 transform.LookAt(target);
 
 transform.position += transform.forward*MoveSpeed*Time.deltaTime;
when i play it the zombie just looks at the character even if its none of the clamped rotations what do i need for it to only use the 90,-90,180 and 0?
               Comment
              
 
               
              Answer by DaveA · Mar 20, 2012 at 11:17 PM
transform.LookAt(target) is going to do that. Remove that.
You can simplify this code a bit:
Angle %= 90;
instead of all the if/then statements, which look very buggy. Ex: Checking > 0 first is also going to catch > 90 and > 180, etc.
ahh thank you and for 0 i could probably do > 360, and what do you mean by Angle %=90 will i replace all the if and if else statements with that?
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                