- Home /
Jump with physics
Hey guys so...i am trying to make a physic based controller with a ragdoll... i made this two lines for jumping : public class Jump : MonoBehaviour { // Start is called before the first frame update void Start() {
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Jump"))
GetComponent<ConstantForce>().force = new Vector3(0, 150, 0);
else
GetComponent<ConstantForce>().force = new Vector3(0, 100, 0);
}
}
and my character keeps floating when i continiously press jump.... my mind cant seem to work with this so i need a little help...how to stop this on a single jump or maybe on a double?
Answer by pmerilainen · May 22, 2019 at 03:18 PM
jumps are actually impulses, so you need to diminish the force over time; after certain time the jump force is zero and gravity starts to overcome the force. you also need to do the controls properly; if you are "in jump" and release the jump button the jump force should be canceled immediately; for single-jump you can jump again after your character has hit the ground, for double jump you can execute second jump from on "jump button down" before ground contact. for good double jump gameplay the second jump needs different force. Tip: animation curves are great when defining force-over time impulses etc.
yeah but becouse my character is a ragdoll to prevent him from crawiling to the floor and actually stand on his feet the 100 force is needed if you get me! can you give me a code example becouse i am really stack here for hours :/
Your answer
Follow this Question
Related Questions
Objects stops if it lands in between two colliders 1 Answer
The player doesn't jump to the left with the W key pressed 0 Answers
Performance Physics.Checkbox/CheckSphere vs Collider/Trigger 1 Answer
3D Hook With Swing Physics 0 Answers
How to Clamp Rotation of a Rigidbody when Using AddTorque 1 Answer