Player doesn't jump (Android)

Hi everyone,
I’m a new member of Unity and of this forum.
I’ve tried to find the answer to my issue, but I haven’t found anything.
I’m creating a platform game, but I can’t make the player jump.
I tried to use Rigidbody2D.velocity, but it doesn’t work and, if I try to use addforce, the jump is unrealistic because the player jumps too fast. The velocity parameter is set correctly, as I can see with Print (Rigidbody2D.velocity). Here is my script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class Salto : MonoBehaviour {

    public float JumpForce;
    public float VelJump;
    public Rigidbody2D rb;
    public bool jump;

    void Start () {
        rb = GetComponent<Rigidbody2D> ();   
    }
   
    void Update () {
        if(CrossPlatformInputManager.GetButtonDown("Jump")) {
            jump = true;
        }

    }

    void FixedUpdate () {
       
        if(jump) {
            //rb.velocity += Vector2.up * VelJump;
            //rb.AddForce(new Vector2(0f, VelJump * Time.deltaTime), ForceMode2D.Impulse);
            // transform.Translate(Vector3.up * JumpForce * Time.deltaTime, Space.World);
            rb.velocity = new Vector2(rb.velocity.x, VelJump);
            jump = false;
            print (rb.velocity);
        }
    }
}

I’ve tried to use also the commented lines, but that didn’t work too.
Is there anybody that can help me?
ps: I’m developing for android devices.

Provided that VelJump has a value other than <= 0, that code would work.
Is there some other portion of your code that is changing the velocity of the character, therefore cancelling this jump action?

As a side note, not to be picky, but I am not sure how you search for jumping in Unity, but I have to imagine that there are many posts on the topic. :slight_smile:

Here the code is completed and it’s the only one that I’ve created in this project. Could it be a Unity’s bug?

Is the rigidbody2d non-kinematic? Does it have ‘simulate’ on? If nothing is happening, and that is your only script, just try adjusting the velJump up higher a little until something happens :slight_smile:

For the record, I do not believe ‘CrossPlatformInput’ is really generally required anymore.
If that is your only script, you can just use ‘Input’ (to the best of my knowledge*) :slight_smile:

1 Like