The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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

func _physics_process(delta):
    var pcol = player.move_and_collide(velocity * delta)
    if pcol:
        velocity = velocity.slide(pcol.normal)

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.

Godot version 3.3
in Engine by (367 points)

2 Answers

0 votes
Best answer

This post answered my question:

moveandslide use moveandcollide internally. It just calls
moveandcollide again once collision is occurred

So now the script looks like this:

func _physics_process(delta):
    var pcol = player.move_and_collide(velocity * delta)
    if pcol:
        velocity = player.move_and_collide(velocity.slide(pcol.normal) * delta)
by (367 points)
0 votes

use this: moveandslide()

by (224 points)

with underscores: moveandslide

Thanks, My aim was more trying to figure out how to make move_and_collide do the same thing as move_and_slide, since move_and_collide is a derivative of move_and_slide.

But thank you!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.