Here is the code for my player movement:
function Update () {
animator.SetInteger("Direction", 4);
if (Input.GetKey(moveUp) && isGrounded == 0)
{
rigidbody2D.velocity.y = jumpheight;
isGrounded = 1;
animator.SetInteger("Direction", 2);
}
else if (Input.GetKey(moveLeft))
{
transform.position += Vector3.left * speed * Time.deltaTime;
animator.SetInteger("Direction", 3);
}
else if (Input.GetKey(moveRight))
{
transform.position += Vector3.right * speed * Time.deltaTime;
animator.SetInteger("Direction", 1);
}
}
And here is the code for the collision:
var PlayerHealth = 100.0;
function Start () {
}
function Update () {
}
function OnCollisionEnter2D(coll: Collision2D) {
if (coll.gameObject.tag == "Ghost"){
PlayerHealth = PlayerHealth - 5.00;
rigidbody.AddForce (Vector3.left * 10);
}
}
The add force has no effect on my character. The collision works though, as the players health goes down. I'm pretty certain it has to do with the transform position in my movement, but I'm not sure how to fix it. Any help?
↧