- Home /
2d jumping, addForce hitting a max height despite force strength
So I have a pretty rudimentary physics-based jumping system, mainly I use rigidbody2d.AddForce to add a force to the up direction. When I use a small value, it does essentially nothing, as the value is just too small to do much of anything. However, after a certain level of force, the height of the jump maxes out and will not go any higher, even if I set the force to a ridiculous value. The mass of the rididbody2d is set to 1.
//check for jumping
if (inputY == 1 && grounded) {
rigidbody2D.AddForce(Vector3.up * 1000000000000);
}
that should be the only relevant code. The max point the gameobject reaches appears to be where his feet reach his head's initial position, and it happens instantly. Gravity does not reduce the object's velocity over any interval. Any thoughts/insights related to the subject are most welcome.
Are you setting the grounded boolean with another gameObject? Does that gameObject have a collider on it? Is that collider set to trigger? Could it be getting stuck with your ground object?
this is my code for setting the grounded boolean: grounded = Physics2D.Linecast (transform.position, GameObject.Find ("groundFinder").transform.position, 1 << Layer$$anonymous$$ask.NameToLayer ("ground"));
where "groundFinder" is a gameobject with only a transform component. It is located immediately below the character. I'm not sure what else could be relevant to the situation, I'm a little stuck at this point.
I don't think the grounded variable is the problem here. Without seeing your level it's hard to say. Could it be an invisible collider somewhere that is preventing it from continuing to jump? What kind of collider does the player have? Just a single capsule collider?
The player has a circle collider at his feet, and a box collider for his body. The character is not animated at this point. This happens no matter what position he jumps from. The character moves horizontally with AddForce in the right and left directions, and works just fine. It is a 2d sidescroller game. I don't know if a gameobject with multiple colliders can have those colliders somehow interfere with each other, I'm just taking shots in the dark.
Do you have any rigid bodies that are children of other rigid bodies involved here?
This caused me some really weird physics behaviour.
Answer by TheFudster · May 19, 2014 at 08:09 AM
I'm seeing the same problem though I haven't solved it. There appears to be a cap on the amount of force that can be applied in one frame maybe? It's very strange. You can make it look good if you scale down your objects and use a smaller orthographic camera size. The demo uses Ortho size 11
Answer by Pyrian · May 19, 2014 at 12:15 PM
That grounded Linecast you're using looks like it's going to hit the Player's own collider and therefore always return true. Thus, you only get one frame of jumping regardless of how high you set the force.
Right but even if you only get ONE frame of AddForce shouldn't it still jump higher when you increase the force value? A larger force value should still accelerate the object to a higher velocity even if it is only one frame. However, we're not seeing that behavior. The acceleration in one single frame seems to be capped somehow.
I'm pretty sure that if you fix your single-frame problem, you're not going to be needing to worry about force/acceleration/velocity caps.
Your answer
Follow this Question
Related Questions
Accelerating speed 2 Answers
Character doesn't jump repeatedly 1 Answer
2d Beat Em Up Jump Functionality 0 Answers