Hi, I managed to get a (more or less) correct collision with a CollisionPolygon2D as a child to a StaticBody2D.
When the Player walks straight against diagonal lines, the chara glides along the collision border. But once she arrives at the corner, the character gets stuck. Only way out is to change the direction away from the collision mesh.
I tried to fix it by making the corners a bit “rounder” by using several points instead of just a single one - but still, same result.
(the transparent stuff is only for adjusting move speed and animation)
The code as text:
var vMoveDirection: Vector2 = Vector2.ZERO # the real physical movement
var vMoveSpeed: int = 300
var vRunSpeed: int = 620
...
func _ready(): #standard, called, when node enters scene first time
pass #ends function if empty
func _process ( delta ): #standard, called every frame. "delta"= time since previous frame
#===== MOVEMENT =====
vMoveDirection.x = Input.get_action_strength("MoveRight") - Input.get_action_strength("MoveLeft")
vMoveDirection.y = (Input.get_action_strength("MoveDown") - Input.get_action_strength("MoveUp"))/2
#===== MOVEMENT SPEED ========
# Walk or Run?
if Input.is_action_pressed("Run"):
velocity = vMoveDirection * vRunSpeed
else: velocity = vMoveDirection * vMoveSpeed
...
func _physics_process( _delta ): # standard, needed for movement
move_and_slide()
...
func fIsDiagonalMovement()-> bool:
if vMoveDirection.x != 0 and vMoveDirection.y != 0:
return true
else:
return false
Thanks
Setting the motion mode to floating worked for the corners, but when walking against a corner I get this weird glitch now (was maybe before too, but not visible because the character was stuck):
It looks like the game wants to let the character slide, but cannot decide in what direction
EDIT: And I have to set the"Wall min slide" to a really low value and I cant use any lines that are exactly in a 90° angle to the character movement. There needs to be at least small difference, so the game knows in which direction the character has to slide.