- Home /
Question by
Ulyas · Jul 24, 2015 at 10:40 AM ·
transformrotateflipside scroller
transform.Rotate(Vector3.up ... not working
I'm trying to rotate my character on the y axis 180 degrees, so he faces the direction he is facing. Side scroller game. The character move just will not face the other direction.
Thank you in advance.
using UnityEngine; using System.Collections;
public class CharacterMovement : MonoBehaviour {
public float maxSpeed = 6.0f;
public bool facingRight = false;
public float moveDirection;
// Use this for initialization
void FixedUpdate ()
{
GetComponent<Rigidbody>().velocity = new Vector2 (moveDirection * maxSpeed, GetComponent<Rigidbody>().velocity.y);
if (moveDirection > 0.0f && !facingRight)
{
Flip();
}
else if (moveDirection < 0.0f && !facingRight)
{
Flip();
}
}
// Update is called once per frame
void Update ()
{
moveDirection = Input.GetAxis ("Horizontal");
}
void Flip()
{
facingRight = !facingRight;
transform.Rotate(Vector3.up, 180.0f, Space.World);
}
}
Comment
Your answer
Follow this Question
Related Questions
Flipping. (transform.Rotate VS transform.localScale) 0 Answers
Flipping ( localscale/rotate unfitting ) 0 Answers
Javascript - Detect wall collision and flip 1 Answer
Trouble with rotating/flipping textures 0 Answers
Rotating a bone via scripts 1 Answer