Should you use physics to move objects on a grid and detect collisions or just use static and set position?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By nwgdusr999

I’ve been trying to code a way to efficiently move objects, and I’ve been flip flopping between going with physics or not going with physics… I basically have a grid, ex; 6x6 and trying to implement dragging and dropping an object on the board to another square. If the moved to square contains an object, move this object to the the dragged object’s original square. (move as in move visually, not teleport to.)

What would you guys recommend, using the physics engine or just detecting the collisions ‘manually’ and moving the static objects using positions? I think either:

  • implementing following mouse pointers using physic forces. (is there a simple way to do this?). Then moving to non-collision layer and move to new spot via forces. (like move to mouse position, easy way to do this?)
  • just using a static RigidBody2D and positioning, doing a manual detecting collisions/intersections and moving via multiple update positions in the physics update method (ex; move X pixels per frame until it reaches location).

I’m not quite sure which would be better… Suggestions? Thoughts? Thanks!

:bust_in_silhouette: Reply From: nwgdusr999

To answer my own question, I was unable to manually work with physics; couldn’t find classes/methods to to the physics computations by hand.

But KinematicBody2D seems to be the way to go for that type of problem. It supports physics collision detection, it’s movement/position isn’t extremely complicated to manage using the physics engine, so that seems like a good solution from my limited experience with it.

So although it might appear to just serve for player controls, I think pretty much anything which requires programmatic location & collision detection is a good fit for it. In my case, I’m moving an invisible one following my mouse location, and all pieces are also KinematicBody2Ds.