How would i detect if the player is standing on a slope?
Asked Answered
B

4

0

So, slopes already work perfectly dure to godot 4's characterbody system, but i have a problem. I want the player to go into a new state when they are crouching and on a slope, but i have no idea how. if possible, could the player's velocity be changed by how steep the slope is? Thanks.

Brainwork answered 19/2, 2023 at 0:21 Comment(0)
L
0

Brainwork
You could use a raycast pointing down and use get_collision_normal().
Also if you are using move_and_collide() it returns collision information including what you are looking for.

Lemberg answered 19/2, 2023 at 15:13 Comment(0)
P
0

Brainwork
Just a sideby question. How did you manage the slopes with the characterbody system?
I always use raycasting so it would be interested every other way.
No little jumps while going downwards on slopes?

Publias answered 9/11, 2023 at 8:11 Comment(0)
B
0

Publias You mean like snapping to the slope? I'd just change the snap_length in the charachterbody floor settings.

Brainwork answered 17/11, 2023 at 19:17 Comment(0)
A
0

My method is in your CharacterBody2D script, check if get_floor_angle() is over let's say 0.4 (you can figure out which angle you want to use. 45 degree is over 0.7 for sure). If it returns a 0, you're on flat ground. if it's over 0.7, you're on a 45. 0.4 is a good round number. I use this to disable running up a 45 degree angle which I use for my staircases.

Alexander answered 18/12, 2023 at 17:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.