0 votes

Hi all, as the title says, I want to change the floor_max_angle but am a little unsure.

Can floor_max_angle be changed in move_and_slide for a KinematicBody2D?

Thank you

in Engine by (810 points)

1 Answer

+1 vote
Best answer

Of course it can. You can pass whatever value you wish when you call move_and_slide().

The default value is 0.785398, which is 45 degrees in radians. Make sure you use radians or convert using deg2rad().

by (18,211 points)
selected by

Thank you. Is it then something like move_and_slide(1.5555)? or do I need to feed it more like move_and_slide.floor_max_angle = 1.55555?

EDIT: love your youtube channel btw. Was just learning from it earliner.

This is no good at all: move_and_slide.floor_max_angle = 1.55555
It's a function, you have to call it with its parameters in parentheses.

Plus, you must pass it a velocity, or you won't move at all anyway.

The doc lists the parameters and they must be used in order:

move_and_slide ( Vector2 linear_velocity, Vector2 floor_normal=Vector2( 0, 0 ), float slope_stop_min_velocity=5, int max_bounces=4, float floor_max_angle=0.785398 )

So you would call it for example, like this:

move_and_slide(Vector2(100, 0), Vector2(0, -1), 5, 4, deg2rad(30))

Thank you. I'll dig in and have a go with that. Your help is really appreciated. I was hoping I could just use moveandslide like I normally do (move_and_slide(motion)) and somehow append a variable for floor angle, but I can see what I have to do now. Thanks again.

Note that many people prefer to define variables for these:

extends KinematicBody2D

var velocity = Vector2(100, 0)
var floor_normal = Vector2(0, -1)
var slope_min_velocity = 5
var max_bounces = 4
var floor_max_angle = PI/4

func _physics_process(delta):
    velocity = move_and_slide(velocity, floor_normal, slope_min_velocity, max_bounces, floor_max_angle)
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.

Categories