Godot: move_and_slide() takes in velocity, while move_and_collide() takes in position offset

Created on 24 Jun 2019  路  4Comments  路  Source: godotengine/godot

Title sums it up, I just found the inconsistency annoying when using those functions. It might be problematic to change it due to backwards compatibility though

discussion physics

Most helpful comment

I agree that it's confusing that the two move_and_* methods have a completely different API: move_and_slide expects velocity and returns the modified velocity, move_and_collide expects an offset and returns a KinematicCollision2D.

In Godot 2 there was only move, which behaved like move_and_collide. move_and_slide was then added, which uses _move internally (which is what move_and_collide binds to).

I find that the KinematicBody[,2D] move API is pretty cumbersome overall, and I hope we can refactor it for 4.0 to be more intuitive and convenient to use (especially regarding the many parameters passed to move_* methods). Currently it's quite inconsistent due to seeing several iterations of improvements while trying to preserve compatibility.

All 4 comments

Is this only about argument name? I don't see a problem. They do two different things, so it makes sense that they aren't named the same.

I agree that it's confusing that the two move_and_* methods have a completely different API: move_and_slide expects velocity and returns the modified velocity, move_and_collide expects an offset and returns a KinematicCollision2D.

In Godot 2 there was only move, which behaved like move_and_collide. move_and_slide was then added, which uses _move internally (which is what move_and_collide binds to).

I find that the KinematicBody[,2D] move API is pretty cumbersome overall, and I hope we can refactor it for 4.0 to be more intuitive and convenient to use (especially regarding the many parameters passed to move_* methods). Currently it's quite inconsistent due to seeing several iterations of improvements while trying to preserve compatibility.

I think it should be move, take an optional parameter slide, and return a collision

@nathanfranke Boolean parameters aren't very readable when you skim over the code, so I'm not sure if it's a good idea.

Was this page helpful?
0 / 5 - 0 ratings