For what is get floor normal () ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lalel345

what is get floor normal() for? I read the KinematicBody documentation but I still don’t understand what its function is and how I should use it.

:bust_in_silhouette: Reply From: Bean_of_all_Beans

I’ll start by defining what a “normal” is, assuming you don’t know what it is.

A normal is used to tell game engine where a mesh’s face is “looking”. An ordinary PlaneMesh that has not been rotated at all will have a normal that is Vector3(0, 1, 0) (equivalent to Vector3.UP). The physics server and the visual server use this information – the physics server for doing physics-y stuff, and the visual server to calculate lighting effects, as well as triplanar texturing.

Now that I’ve described it (or if you already knew it), the KinematicBody function get_floor_normal() returns the normal of the floor the body is standing on. If you want to root your KinematicBody to the sloped surface of a ramp, you can use KinematicBody.get_floor_normal() to get the normal of the ramp, then have gravity for KinematicBody move the body in the opposite direction, thus rooting the body in place.
Maybe you want to make a jump pad. Using KinematicBody.get_floor_normal() will tell you where to push your KinematicBody.
Really, there are more than likely more uses for get_floor_normal than I’ve listed, but those were just some things I came up with on the spot.

then if the kinematic player is move_and_slide in floor I must call get_floor_normal method??

lalel345 | 2020-10-13 12:10

If the KinematicBody gets stuck in the floor, you can move it out using the normal. To keep the KinematicBody glued to the floor (so as to not slide down a ramp when idle), I would use -get_floor_normal(). All the function does it tell you what the KinematicBody thinks is the floor normal; it won’t move the body on its own, instead returning a Vector3.

Bean_of_all_Beans | 2020-10-13 21:47

1 Like