Character Script cant jump

#pragma strict

private var characterAnimator : Animator;
var speed : float = 3;
var grounded = false;
var jumpHeight : float = 3;

function OnTriggerEnter2D(colenter : Collider2D)
{

grounded = true;
}

function OnTriggerExit2D(colexit : Collider2D)
{
grounded = false;
}

function Awake()
{
characterAnimator = gameObject.GetComponent(“Animator”);
}

function Start()
{
jumpHeight = jumpHeight * 100;
}

function Update()
{
if (Input.GetKey(KeyCode.A))
{
gameObject.transform.position.x -= speed * Time.deltaTime;
gameObject.transform.rotation.y = 180;
characterAnimator.SetBool(“walking”, true);
}
else if (Input.GetKey(KeyCode.D))
{
gameObject.transform.position.x += speed * Time.deltaTime;
gameObject.transform.rotation.y = 0;
characterAnimator.SetBool(“walking”, true);
}
else
{
gameObject.transform.position.x += 0 * Time.deltaTime;
characterAnimator.SetBool(“walking”, false);
}

if (Input.GetKeyDown(KeyCode.Space))
{
if (grounded)
{
gameObject.GetComponent.().AddForce(Vector2.up * jumpHeight);
grounded = false;
}
}
}

this is a character script i cant get my character in my game to jump Can you help me with this i would appreciate it thank you

This is written in javascript

Can you use code tag ?

If you can’t jump, it may be because the boolean “grounded” never become “true”.
You should write " Debug.Log(grounded); " in your update function to confirm this idea.

If it’s really the problem, than the OnTriggerEnter2D is the source of the trouble. I’m not familiar with it so i can’t really help. I personnaly use a raycast to detect if i’m grounded or not in my games. I’m not working in javascript but if you want a sample of C# script for this kind of raycast i can help you :wink:

Hey do you want to join me on creating this game :smile: i need someone who can code and im doing the textures

It would have been a pleasure but i’m already on several project which are taking me a lot of times. If you need a programmer you should visit the collaboration chanel of the forum

Ok thanks i appreciate it