- Home /
Rigidbody Character Jumps Higher With At Least 2 Collisions
Hi, and thanks for taking the time to read my question. Lately I've been working on a rigid-body character controller for my next project, so far everything but the jumping is working correctly. If I just jump then it works fine... but if the player's rigid-body is colliding with any colliders then the player can jump just about twice as high (the more colliders, the higher the jump). The orientation of the colliders doesn't seem to matter just so long as they are touching the player in some way. This is the only code in the controller relating to jumping, and is very similar to that used in the rigid-body walker on the wiki (which also suffers the same problem). Ive tweaked the physics material of the player and walls and neither makes any difference in the behavior. Any insight at all would be greatly appreciated, thanks.
Edit: Almost forgot BodyController.cs is the full script i'm using. Edit Again: I just noticed that my jump height is in fact being altered when I collide with just one collider, but by very little, it seems that my height exponentially increases with the number of colliders.
private float CalculateJumpVerticalSpeed () { return Mathf.Sqrt(2 * JumpHeight * Gravity); } // Jump if (JumpKey && !CamController.isShaking && !CamController.Cinematic) { VelocityChange.y = CalculateJumpVerticalSpeed (); VelocityChange.y = (VelocityChange.y - Velocity.y); } rigidbody.AddForce (VelocityChange, ForceMode.VelocityChange); rigidbody.AddForce (new Vector3 (0, -Gravity * rigidbody.mass, 0));
[1]: /storage/temp/2761-testpackage.zip
I've had something similar happen. When my rigid body runs into another moving rigid body it jumps twice as high (without a jump call). This just randomly happens. I never figured out the solution.
Please could you upload a $$anonymous$$imalistic unitypackage? I would like to debug in the same conditions as yours.
Of course, anything that helps. A package with everything you need (hopefully i didn't miss something, the code is a bit spread since i'm changing how i'm handling inputs) has been added as an attachment. Just place box-colliders with the "Walls" Physics material, a floor with no set physics material, and an instance of the Player prefab and you should be fine (you will have to set up the project input settings however). The problem is most noticeable when trying to jump in a corner formed by two walls.
Answer by CharlesD · Aug 14, 2012 at 05:53 AM
Well, don't you just hate it when you ask a question only to have an epiphany hours later that solves it? I've been playing with the physics variables, changing the methods used for jumping, and running full line graphs on just about every variable I could find trying to understand whats wrong, and nothing has worked. As it turns out all I had to do was add a rigid-body component to all of the existing game-objects with colliders and set them to kinematic. Maybe there is something in the unity documentation that I missed, but I never knew that rigid-bodies wouldn't behave correctly if the objects they were colliding with didn't have rigid-bodies of their own. Hopefully this helps someone in the future.
Really helpful solution to some strange Unity behavior. Helped a lot in maintaining a maximum jump height in a marble-like game. Thx!
This exact thing worked for me as well. I have no idea why this is the case though. Perhaps it's a bug.
Thank you very much,CharlesD,your answer have solved my problem too! I have been confused with the similar problem for several days.$$anonymous$$y problem is that my ground is not just one object, it's a lot of blocks that combines it.If my player stand on the bound of the block or on two blocks the same time,my player will jump alomost twice higher than usual just like the above friend said.After I add rigidbody component to all my ground objects, it did solved the problem!!Thanks a lot, next time I will try character controller component ins$$anonymous$$d of the rigidbody.
Another victim of this issue. You try to be efficient by not using rigidbodys when you don't need it, and you get burned. This issue gave me a headache last night and put me to sleep. Great fix around what seems like a Unity bug.
Answer by Tofa · Oct 31, 2014 at 11:28 AM
My answer to this is about 2 years too late :-), but may be useful for others who see this...
I propose that the issue here is the one I found here: http://answers.unity3d.com/questions/818801/why-are-rigidbody-interactions-only-consistent-whe.html
In short, if you are using Unity's gravity you may be experiencing this issue. If you use a custom gravity as described in the above link you can avoid having to set a whole bunch of objects to be rigidbodies.
Answer by Jakeaby · Aug 19, 2020 at 12:32 AM
Hello guys, I had this same issue but I was unable to fix it. I use unity 2019.3 and I fixed it by using rigidbody.velocity instead of the AddForce();.
Something like this: rigidbody.velocity = Vector2.up * jumpForce;