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.