Question by
VihanAgarwal · May 18, 2016 at 07:23 AM ·
rigidbody2d
My character is flipping but not moving?
using UnityEngine; using System.Collections;
public class playerController : MonoBehaviour {
private Animator playerAnim;
private Rigidbody2D playerBody;
public float maxSpeed;
bool grounded;
bool isFacingRight;
// Use this for initialization
void Start () {
grounded = true;
playerBody = GetComponent<Rigidbody2D> ();
playerAnim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
float moveInp = Input.GetAxis("Horizontal");
playerBody.velocity = new Vector2 (moveInp * maxSpeed, playerBody.velocity.y);
if (moveInp > 0) {
gameObject.transform.rotation = Quaternion.Euler (new Vector3 (0, 0, 0));
isFacingRight = true;
} else if (moveInp < 0) {
gameObject.transform.rotation = Quaternion.Euler (new Vector3 (0, 180, 0));
isFacingRight = false;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Unity2D Choppy Slerp Update,,Rigidbody rotation choppy in update 0 Answers
rigidbody2D.velocity 0 Answers
How to use Rigidbody2D.MovePosition to move a kinematic object around looping waypoints? 1 Answer
How can I slow the movement of a single rigidbody2D? 2 Answers
Freeze all falling objects on y-axis 0 Answers