- Home /
2D Character Jumps only 1 time
I used a video tutorial to make my 2dChar jumping but the Character jumps only 1 time after pressing space. Unity isn't showing errors :/
// Char Speed
var moveSpeed = 4f;
// Jump Player
var jumpHeight : float = 500;
var isJumping : boolean = false;
function Update () {
Movement ();
}
// Movement and Jump
function Movement () {
if(Input.GetKey (KeyCode.D))
{
transform.Translate(Vector2.right * moveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(-Vector2.right * moveSpeed * Time.deltaTime);
}
if(Input.GetKeyDown(KeyCode.Space))
{
if(isJumping == false){
rigidbody2D.AddForce(Vector2.up * jumpHeight);
isJumping = true;
Debug.Log("isJuming");
}
}
}
// Player is on Ground - for Jump
function OnCollisionEnter2D(col : Collision2D )
{
if(col.gameObject.tag == "Gass")
{
isJumping = false;
Debug.Log("NoJumping!");
}
}
I hope you can help me,
Greetings GreenTee :)
I don't understand, do you want your player to jump only if he is on ground?
Answer by screenname_taken · Jul 25, 2014 at 12:42 PM
Are you 100% sure that the tag you are using is the right one? i mean the string and tag are exactly the same.
Answer by jmgek · Jul 25, 2014 at 01:49 AM
isJumping = true;
Makes it stay true, forever.
float nextTimetoJump;
void Start()
{
nextTimetoJump = 3;
}
void Update()
{
nextTimetoJump -= Time.deltaTime;
if( nextTimetoJump < 0 && Input.GetKeyDown(KeyCode.Space))
{
Movement ();
nextTimetoJump = 3;
}
}
now the Jump works but my character is able to jump in the air. I don't understand why "OnCollisionEnter2D" doesn't work.
Your answer
Follow this Question
Related Questions
CharacterMotor problem (Js) 1 Answer
Moving Character in Midair? JS 0 Answers
How to make smooth jump? 1 Answer
Particular "Jump" Script. 2 Answers
I am trying to make a movement script for my main camera but it isnt working! 2 Answers