I’m currently working on a side-scrolling game.
Among them, I made the stair tiles into a slope shape with physics collision. It works fine when the player passes by, but sometimes the state changes and the controls don’t work.
Here’s the player code for this part:
if not player.is_on_floor():
state_machine.transition_to(“FALL”)
return
The picture is the shape of the composed physics collision and the state of the state when the problem occurs. I think the problem is that is_on_floor() returns true and false alternately in the shape of the slope. I also tried adjusting the maxangle and snap length, safe margin of the character body2d item, but this phenomenon persists. Is there a solution for this?
You might get some chaos in the player CharacterBody2D, like
func _physics_process(delta: float) -> void:
# You wrote your code here, which is not cool
move_and_slide()
velocity.y += gravity
# You wrote your code here, which is not cool too
To make physics as smoothest as possible, the order of the move_and_slide() method and the velocity.y += gravity statement is
func _physics_process(delta: float) -> void:
# You wrote your code here, which is awesome
velocity.y += gravity
move_and_slide()
# You wrote your code here, which is awesome too
The part about velocity.y is in another class, so I temporarily commented it out for testing and processed it before move_and_slide(). However, is_on_floor() in the slope still keeps spitting out true and false.
난 이 문제를 완벽하게 해결하진 못했지만, 일말의 가능성을 얻었습니다.
characterbody에서 constant speed를 체크하고, snap length를 조절하면 이 문제가 확연히 줄어듭니다. 아마도 캐릭터가 경사로에서 이동할 때, 지면에 딱 붙지 못하여 is_on_floor()의 값이 들쑥날쑥했던 것 같습니다.