- Home /
Hi.somebody can explain me why this jump ball script doesnt work?.Thanks
Is only one ball whit rigidbody and jump script .The ball is over a plane.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class jump_ball : MonoBehaviour {
public float jumpValue=100.0f;
private Rigidbody rb;
// Use this for initialization
void Start () {
rb=GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate () {
if(Input.GetButtonDown("Jump") && Mathf.Abs(rb.velocity.y)<0.01f)
rb.AddForce(Vector3.up*jumpValue,ForceMode.Impulse);
}
}
Try lowering rigidbody Gravity and see what happens. maybe its not enough force to get it off the ground.
Answer by Captain_Pineapple · Jun 06, 2018 at 08:02 AM
Hey there,
you could try some things to fix your script: First up try to increase the force you apply, if your rigidbodys mass is over 1 your body is too heavy to jump. Next up check if the force in the public variable in your object in the scene actually has the right value.
Add a Debug.Log() to see if your code acutally is called:
void FixedUpdate () {
if(Input.GetButtonDown("Jump") && Mathf.Abs(rb.velocity.y)<0.01f)
{
Debug.Log("jumping with force: "+ jumpValue);
rb.AddForce(Vector3.up*jumpValue,ForceMode.Impulse);
}
}
In case this Log is NOT called remove the condition of the velocity check (you probably want to change this condition to some "I am on ground condition" instead). If it still is NOT Called check which Button is actually bound to the "Jump" Button. You could try to work around this by timewise using Input.GetKeyDown(KeyCode.Space); If this still does not work come back here.
Hope this helps. In future please add Debug logs and so on to your code so that we may see that you already checked possible more obvious problems like the AddForce not beeing called at all.
Your answer
Follow this Question
Related Questions
Jumping in 3D 1 Answer
How to make Sphere to jump? 2 Answers
my character get by jumping 1 Answer
Jumping in only the direction of the last key pressed 0 Answers
Player Controls 0 Answers