- Home /
Question by
EternalAshley · Dec 10, 2014 at 02:25 AM ·
collisioncollider2d game
2D:I have a movementController script on my character but it doesn't move forward
I have a movement controller script on my character but my character doesn't move forward or flip around like it is supposed to. My character has a rigidbody applied as well as a box collider around the body and a circle collider around the feet. This is the code I have applied:
using UnityEngine;
using System.Collections;
public class MovementController : MonoBehaviour
{
public float maxSpeed = 10.0f;
bool facingRight = true;
Animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void FixedUpdate ()
{
float move = Input.GetAxis("Horizontal");
anim.SetFloat("Speed", Mathf.Abs (move));
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.x);
if(move > 0 && !facingRight)
{
FlipFacing();
}
else if(move < 0 && facingRight)
{
FlipFacing();
}
}
void FlipFacing()
{
facingRight = !facingRight;
Vector3 charScale = transform.localScale;
charScale.x *= -1;
transform.localScale = charScale;
}
}
Comment
Your answer
Follow this Question
Related Questions
Create a collider for area created by mouse 0 Answers
Trigger2D not working 0 Answers
*** Trigger Collider2D event only once *** 3 Answers
How can I destroy an object if it touches NOTHING 1 Answer
Creating 'redstone' like wires 1 Answer