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.

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.

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 `get`

, which looks like this:*collision*normal()

https://www.geogebra.org/m/gqmbHdx6

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:

https://www.geogebra.org/m/rV4kSCre

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.

http://docs.godotengine.org/en/latest/tutorials/_misc_tutorials.html

- All categories
- Engine 33,363