- Home /
Question by
ABy_ hijjawi · Apr 03, 2014 at 08:55 AM ·
ground detectionpublic static1 frame
how to make sprite player jump for a fixed distance
how to make sprite player jump for a fixed distance in unity 2d,when I have used the code bellow. The sprite moves to up ,it doesn't return back to the ground , I have added rigidBody2d(); Could you help me?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class RunTest : MonoBehaviour
{
public static bool jumpBool =false;
public bool grounded = true;
public int jumpSpeed = 1;
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode .Space))
{
if(grounded==true){
rigidbody2D.AddForce(Vector3.up * 1f);
grounded= false;
jumpBool = true;
}
}
}
}
Comment
You apply a force to move the sprite upwards, but you never appear to apply a force to move the sprite down again. (Or remove the force and let it fall under gravity.)
Your answer
Follow this Question
Related Questions
Public static variable not updating from void Start ()? 2 Answers
Check if circle player is on the ground 4 Answers
How can I put a limit on "in-air dashes?" 0 Answers
How do I get this to work? 1 Answer