Hey guys,
I decided to test my skills and go ahead and make a 2D platformer. Anyway sometimes when i walk along the ground i stop walking and it seems like a invisible object is in front of me. Heres a clip:
link text
Hope you can see my problem… ask all the questions ya want
also here’s the code for my player controller (Sorry please excuse my bad coding habits :)) :
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public int playerNumber;
public float moveSpeed;
public float jumpForce;
private Rigidbody2D rb;
private float moveVelocity;
private Animator anim;
private Collider2D coll;
public LayerMask ground;
private bool grounded;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
coll = GetComponent<Collider2D>();
}
// Update is called once per frame
void Update () {
if (coll.IsTouchingLayers(ground))
{
grounded = true;
}
else
{
grounded = false;
}
moveVelocity = 0f;
if (Input.GetKey(KeyCode.D))
{
moveVelocity = moveSpeed;
}
if (Input.GetKey(KeyCode.A))
{
moveVelocity = -moveSpeed;
}
if (grounded)
{
if (Input.GetKeyDown(KeyCode.W))
{
Jump();
}
}
rb.velocity = new Vector2(moveVelocity, rb.velocity.y);
anim.SetFloat("Speed", Mathf.Abs(moveVelocity));
anim.SetBool("Grounded", grounded);
if (rb.velocity.x > 0)
transform.localScale = new Vector3(1f, 1f, 1f);
else if (rb.velocity.x < 0)
transform.localScale = new Vector3(-1f, 1f, 1f);
}
public void Jump()
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
}