Issues with Jump Script in C#
I have a problem where my jump forces my sprite directly to a certain location, basically jumping without the ascension upwards. I'm still not sure how I can fix it, and, to kill two birds with one stone, I was wondering if anyone could help me out with allowing jumping only once (from the ground). My code is posted below:
using UnityEngine;
using System.Collections;
public class PlayerJump : MonoBehaviour {
Rigidbody2D rbody;
void Start() {
rbody = GetComponent<Rigidbody2D> ();
}
void Update() {
if (Input.GetKeyDown (KeyCode.Space)) {
Debug.Log ("jump is working");
rbody.AddForce (new Vector2 (0, 10), ForceMode2D.Impulse);
}
}
}
I am getting the "jump is working" message, so I know pressing space runs the if statement. If anyone can shed some light on what I'm doing wrong, I'd greatly appreciate it.
Thanks in advance.
try replacing :
rbody.AddForce (new Vector2 (0, 10), Force$$anonymous$$ode2D.Impulse);
with
rbody.AddForce (rbody.position + new Vector2 (0, 10), Force$$anonymous$$ode2D.Impulse);
Your answer
Follow this Question
Related Questions
Highscore not showing up 1 Answer
Coroutines not running one after another 1 Answer
public rigidbody in Javascript 1 Answer
unable to attack enemy objects? 1 Answer
Rayscast from the GameObject that is not the player does not work 0 Answers