+2 votes

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.

in Engine by (183 points)

1 Answer

+1 vote

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.

by (329 points)

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

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.

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 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 webmaster@godotengine.org with your username.