- Home /
Question by
Fulano_ · Sep 09, 2014 at 02:57 AM ·
javascriptjumpsidescroller
unity2d javascript jump help
Trying my best at a 2d side scrolling infinite runner, but I cant seem to get the character to jump. When I press space he starts flying up constantly without coming down. Please help me out, and thanks in advance.
#pragma strict
var myForce : float = 25;
var jumpForce : float = 25;
function Start () {
};
function Update () {
if(Input.GetKeyDown(KeyCode.Space));
{
rigidbody2D.AddForce(Vector2.right * jumpForce);
};
};
function FixedUpdate () {
rigidbody2D.AddForce(Vector2.right * myForce);
};
Comment
var jumpForce : float = 500;
function Update()
{
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
{
rigidbody2D.AddForce(new Vector2(0, jumpForce ));
}
}
//don't forget to add rigidbody2D to your object and set your gravity to 1.
Thank you so much, Jeric $$anonymous$$iana, it works now! :)
Answer by iamthecoolguy11 · Sep 09, 2014 at 03:06 AM
turn the "jumpForce" up to like 1000.
var myForce : float = 25;
var jumpForce : float = 1000;
function Update () {
if(Input.GetKeyDown(KeyCode.Space));
{
rigidbody2D.AddForce(Vector2.up * jumpForce);
}
}
function FixedUpdate()
{
rigidbody2D.AddForce(Vector2.right * myForce);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613162613im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to have animation play correctly 1 Answer
PlayerPrefs Scripting Logic Help! 1 Answer
rigidbody.AddForce to another object 2 Answers
ai navigation help 0 Answers