I've tried doing what the docs say:
For example, the following two code snippets result in the same
collision response:
# using move_and_collide
var collision = move_and_collide(velocity * delta)
if collision:
velocity = velocity.slide(collision.normal)
# using move_and_slide
velocity = move_and_slide(velocity)
But this NOT the case, I have practically copied this script verbatim and the 'Player is still stopped on staticbody2D
. It is some how STILL colliding and just choosing to stop instead of sliding across if approached at a diagonal vector. If only goes across a staticbody2D
if I only press a perpendicular direction to it.
Here is MY script:
const speed = 500
var velocity = Vector2()
func get_input():
velocity = Vector2()
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if Input.is_action_pressed("ui_down"):
velocity.y += 1
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
if velocity.length() > 0:
velocity = velocity.normalized() * speed
#print(velocity)
func _physics_process(delta):
get_input()
var pcol = player.move_and_collide(velocity * delta)
if pcol:
velocity = velocity.slide(pcol.normal)
print(velocity)
I've tried taking the velocity and stepifying the axis that is being nullified by the slide()
, in order to make sure it's zeroed out, but it doesn't matter, it still colliding. I believe it's because it's calling the var pcol
first before its collision, so it just rapidly fires a stop.
Is there a way to use moveandcollide without it stopping at very staticbody2D
? I want it to just slide along it.