character jump is jerky
I have a 2D square sprite I'm using as the main character. Movement left and right work which I have in another script. the jump I'm putting in its own script.
I'm using Addforce on the rigidbody2d component attached to the sprite and it works. however the way he jumps is not ideal. The square teleports up then falls back down regularly. What I want is a natural looking jump, not a teleport. I've tried so many other methods after addforce and nothing works. Here is the script. I'm new at this so sorry if the script looks silly. I would really appreciate some help on this. The addforce happens under FixedUpdate.
public class PlayerJumpModified : MonoBehaviour {
[SerializeField]
public Vector3 jumpForce = new Vector3(0f, 10f, 0f);
private BoxCollider2D playerCollider;
private Rigidbody2D playerRigidbody2D;
private bool playerGrounded = false;
// Use this for initialization
void Start () {
playerRigidbody2D = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void FixedUpdate () {
if (playerGrounded == true) {
if (Input.GetKeyDown ("space")) {
playerRigidbody2D.AddForce(jumpForce, ForceMode2D.Force);
Your answer
![](https://koobas.hobune.stream/wayback/20220612070224im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
addForce problem please help! 2 Answers
bullet wont move forward 2 Answers
Ball Speed is not increasing as per code 0 Answers
addforce the force keeps on adding. 0 Answers
Why doesn't my knockback function apply force to it's target? 1 Answer