- Home /
 
              This question was 
             closed Oct 13, 2012 at 08:27 AM by 
             whydoidoit for the following reason: 
             
 
            OP couldn't edit the question to get the right code in. Has now posted a new question.
Rotate model, turn around only, no bend?
I have this code attached to a model, the model is meant to turn and face the player wherever they go. But the enemy seems to bend backwards if the player gets close, how can I make him turn only?
 var walkSpeed: float = 3; // Walk Speed
 var runSpeed: float = 6; // Run Speed
 var footsteps : AudioClip; //Walking SFX
 var Stamina = 100; //Stamina
 
 private var chMotor: CharacterMotor;
 private var tr: Transform;
 private var dist: float; // distance to ground
 
 function Start(){
     audio.clip = footsteps;
     audio.loop = true;
     
     chMotor = GetComponent(CharacterMotor);
     tr = transform;
     var ch:CharacterController = GetComponent(CharacterController);
     dist = ch.height/2; // calculate distance to ground
 }
 
 function Update(){
     var vScale = 1.0;
     var speed = walkSpeed;
 
     // If a WASD button has been pressed, play sound
     if (Input.GetKeyDown (KeyCode.W) || Input.GetKeyDown (KeyCode.A) || Input.GetKeyDown (KeyCode.S) || Input.GetKeyDown(KeyCode.D))
     {
         // Only start playing, if the audio hasn't been started yet
         if(!audio.isPlaying)
             audio.Play();
     }
     // If none of the WASD buttons are pressed, stop sound
     else if(!Input.GetKey (KeyCode.W) && !Input.GetKey (KeyCode.A) && !Input.GetKey (KeyCode.S) && !Input.GetKey(KeyCode.D))
         audio.Stop();
                 
     if (chMotor.grounded && Input.GetKey("left shift") || Input.GetKey("right shift")){
         speed = runSpeed;
     }
     
     chMotor.movement.maxForwardSpeed = speed; // set max speed
     tr.localScale.y = Mathf.Lerp(tr.localScale.y, vScale, 5*Time.deltaTime);
 }
 
              
               Comment
              
 
               
              This looks more like the player script! Is this the right script?
Yeah you was right, I must of posted the wrong code whilst half asleep... It won't let me edit so I'll re upload as a new answer.
Follow this Question
Related Questions
Raycast Rotate Help 1 Answer
Weird rotation shapes 1 Answer
Rotating to -forward goes upside down 1 Answer