This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I need to figure our which mesh my kinematicbody is colliding with from a gridmap. I need to determine if it is a ramp so that I can rotate the body to make it go over the ramp.

in Engine by (15 points)

1 Answer

0 votes

I think you can't really find it out. You can only trying to figure which cell was at the collision point.
But if you only want to know if your body is colliding with a ramp, you can check the normal of the collision. If it's not straight horizontal (a wall) or vertical (the floor), then it's a ramp.

by (703 points)

Thank you for your help, but I don't understand how to do this. How do I find the angle from the Vector3?

Since you're using a KinematicBody, it has the method getcollisionnormal(), which looks like this:

After that, a dot product of the normal on the velocity will tell you if it's perpendicular (vertical wall, dot product being zero) or something else.
To know where to orient your body to climb up the ramp, doing the dot product of the up vector (Vector3(0,1,0)) on the normal, then multiply the result to a normalized vector of the normal, then substract it from the up vector to get the final vector that slides along the ramp towards the top:

Thank you! How do I figure out how to rotate my body with this?

There are many different ways to do it. But the simplest is to create a transform, for instance with the method looking_at, and apply it to the node.

And if you still didn't do it, you should definitely read the official documentation about vectors and transforms. It explains the fundamentals about all this and it contains lot of examples in gdscript.

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.