0 votes

My character is a box shaped, rigid body 2D set on rigid mode. I want it to only be able to jump when one of its edges is in full contact with the floor. Something like this:

enter image description here
I thought of checking the angle of the player, but that wouldn't help if i'm standing over something like a ramp.

in Engine by (29 points)

2 Answers

0 votes

How about a bunch of really short RayCast2Ds from the player's feet, and allow him to jump only if all of them return collision?

The problem with raycasts is you'll have to add exceptions for everything that's not floor or just use separate collision layer only for them and the floor. I think it's the simplest solution though.

by (39 points)
+3 votes

Take your transformation's y-axis:

var yaxis = global_transform.basis.y

Then compare the axis with your floor's normal with a dot product.

var can_jump = -dot(yaxis, normal) > 0.95
by (3,936 points)

You do know how to get the floor's normal right?

The basis doesn't seem to work for Transform2D...

My bad. I was thinking of the 3D counterpart. Change that line to this.

var yaxis = global_transform.y

I already have the normal vector of the floor, it's solved now, thank you :D!

Your welcome. And if you want to..

Vote n' Select ;)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.