Can floor_max_angle be changed in move_and_slide for a KinematicBody2D?

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

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

:bust_in_silhouette: Reply From: kidscancode

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().

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.

Robster | 2018-02-23 06:14

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))

kidscancode | 2018-02-23 06:22

Thank you. I’ll dig in and have a go with that. Your help is really appreciated. I was hoping I could just use move_and_slide 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.

Robster | 2018-02-23 06:25

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)

kidscancode | 2018-02-23 06:25