- Home /
 
Rotating A Character 180 Degress
So, I'm working on a 2D platformer. But, I'm editing the FPSWalker script to fit my needs. I want the character to rotate 180 degrees on the Y-Axis depending on which direction he's moving. How could I do this? I know that their's transform.rotate, but my brain is trying to comprehend..
 var playerSpeed = 15.0; var jumpSpeed = 15.0; var gravity = 20.0;
 
               var AntiBunnyHop = 1;
 
               private var moveDirection = Vector3.zero; private var grounded : boolean = false; private var jumpTimer : int;
 
               function Start () { jumpTimer = AntiBunnyHop; }
 
               function Update () { if (Input.GetButton("Attack")) { BroadcastMessage("Fire"); } if (Input.GetButton("Attack 2")) { BroadcastMessage("Fire2"); } transform.position.z = 0; }
 
               function FixedUpdate () { if (grounded) { //Haha, your on the ground you loser. moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0 , 0); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= playerSpeed;
 
                    if (!Input.GetButton("Jump"))
         jumpTimer++;
     else if (jumpTimer >= AntiBunnyHop) {
         moveDirection.y = jumpSpeed;
         jumpTimer = 0;
     }
 }
 
               // Apply gravity moveDirection.y -= gravity * Time.deltaTime;
 
                // Move the controller
 var controller : CharacterController = GetComponent(CharacterController);
 var flags = controller.Move(moveDirection * Time.deltaTime);
 grounded = (flags & CollisionFlags.CollidedBelow) != 0;
 
               }
  
               @script RequireComponent(CharacterController)  
Answer by e-bonneville · Jun 26, 2010 at 07:49 PM
Use this:
function Update () {
    if (Input.GetButtonDown("Fire1")) {
        transform.eulerAngles = Vector3(0,180,0);
    }
}
 
               
               to turn your character around.
Your answer
 
             Follow this Question
Related Questions
How to rotate Character depending on the inclination of the platform or its parts? 1 Answer
0-360 Y degree from Vector3.Angle 1 Answer
90 degrees isnt? 2 Answers
Limit Object Angle 2 Answers