- Home /
Why can't I properly jump?
Hello, merry Christmas!
When I'm on the "proper" ground (in this case a platform), I can jump with proper force. (The platform has a "Ground" layer set). But when I jump on the "Commercials", which are also set on the "Ground" layer, my first jump on them is noticeably weaker. The commercials have a BoxCollider2D, but they are intentionally set on Trigger, because I don't want the player to be able to walk on the commercials, but rather use them as an opportunity to jump onto another commercial and so on.
![alt text][2] [2]: /storage/temp/150526-weirdjump2.gif
The first script:
This is the second script:
public class Controller : MonoBehaviour
{
public CharacterController2D controller;
float moveHorizontal;
public float speed;
bool jump = false;
void Update()
{
moveHorizontal = Input.GetAxisRaw("Horizontal") * speed;
if (Input.GetButtonDown("Jump"))
{
jump = true;
}
}
void FixedUpdate()
{
controller.Move(moveHorizontal * Time.deltaTime, jump);
jump = false;
}
}
Check in the settings that QueryTriggerInteraction
is set to true, it migth be that when you are raycasting to test for ground its not querying the trigger collider.
Where do I find this "QueryTriggerInteraction"?
Edit -> Project Settings -> Physics/Physics2D
Also you can often set this in the Raycast too.
Answer by Twinklier · Dec 29, 2019 at 07:27 AM
Imagine this in slow motion. You hit jump, you add force m_JumpForce, you go up, and slowly fall. You have a downward velocity. You jump again, adding force, but that has to fight with the donward velocity.
It's like when you're falling from a plane, you can't just take off you shoes and jump on it to break your fall. Yes, you'd slow down slightly with the force from that jump, with it's not enough to counteract the speed of your fall. You'd have to completely remove your downward velocity before you do a second jump.
Just getting you into the mindset, enough of the bs.
Just set your m_RigidBody.velocity = new Vector3(m_RigidBody.velocity.x, 0, m_RigidBody.velocity.z); right at the instance before you addforce. This ensures that the downward velocity is 0, thus you addforce wouldn't have to fight anything. Or, directly change your velocities (m_RigidBody.velocity += Vector3.up * m_JumpForce) . This ensures that every jump, you starting upward velocity is the same.
Cheers!
Answer by marioluigivideo · Dec 30, 2019 at 10:03 AM
Hey, here's a video of Brackeys where he uses the same Player Controller script as you: https://www.youtube.com/watch?v=dwcT-Dch0bA If you follow his instructions, your problem will certainly be solved.