- Home /
UI jump button and isgrounded using Rigidbody
so i have a movement script that's for a mobile game using UI button, ive already got the movement for X & Z (forward and sideward) but i couldnt get how to jump using UI button and isGrounded bool using Rigidbody (whenever i click the UI jump button it does an infinite jump because the isGrounded isnt working) i only intended it to jump once, i know how to do it for a character controller so i thought its the same process but it still didnt work, anyway this is how i did the jump script
Rigidbody rb;
public Vector3 jump;
bool isGrounded; //im lost on how im gonna incorporate this
public float jumpForce = 5.0f;
void Start()
{
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 5.0f, 0.0f);
}
public void Jump()
{
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
}
//there was suppose to be another public void script here for the pointerUp in the event trigger but i lost my mind trying to find a way to make use of it
Can you explain:
What currently happens when you call Jump()?
And What you expect to happen instead?
Also do consider that you are using:
jumpForce = 5.0f;
jump = new Vector3(0.0f, 5.0f, 0.0f);
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
Giving a total Magnitude of 25.
Would be cleaner to do:
jump = Vector3.Up;
jumpForce = 25.0f; // Or 5.0f if that was the intended magnitude
so when i call a jump using the UI button it just did as intended to jump but because i couldnt find a way to use isGrounded using Rigidbody i can infinitely jump everytime i click the ui button, and thats what im having a hard time solving, is how you incorporate isGrounded on a Rigidbody not a character controller on a UI button input for mobile games
Answer by Caeser_21 · Mar 20 at 05:29 PM
For the "IsGrounded" bool, you could use Raycasts if nothing else work... I could also send over the code if you want.
Your answer
Follow this Question
Related Questions
how to control player movement with ui buttons? 1 Answer
Can Someone Help me with my Onclick Jump Button to only fire only if Grounded 1 Answer
Detecting which UI button was pressed within canvas? 1 Answer
Buttons are clicked when i click on a text away from the button but its a child of the buttong 1 Answer
Button gets stuck in Pressed state 1 Answer