Hey guys !
I’m nem to unity and have created this basic movement script so i can do some tests and learn a bit following the 2d platformer tutorial but there’s a little problem, here’s the code :
using UnityEngine;
using System.Collections;
public class controller : MonoBehaviour {
public float speed = 10f;
Rigidbody2D rb2d;
public float jumpPower = 1000;
bool grounded;
void Start ()
{
rb2d = GetComponent<Rigidbody2D> ();
}
void Update ()
{
if (grounded && Input.GetKeyDown(KeyCode.Space))
{
rb2d.AddForce (new Vector2 (0, jumpPower));
}
}
void FixedUpdate ()
{
float move = Input.GetAxis ("Horizontal");
rb2d.velocity = new Vector2 (speed * move, rb2d.velocity.y);
}
void OnTriggerEnter2D(Collider2D other)
{
grounded = true;
}
void OnTriggerExitr2D(Collider2D other)
{
grounded = false;
}
}
my character doesn’t want to jump even if it’s colliding , so that left me wondering if the OnTriggerEnter/Exit2D isn’t working for my script
Any ideas ?