How to create boundaries for draggable objects so it can't pass

boundary2

Want to make draggable objects don’t pass some defined boundaries. I’m using collision detection with boundraies but it just passses while dragging.

Hi! Collision detection won’t help you here. The easiest thing is editing the code that you’re using to drag things around the screen. Can we see your code?

Merge.zip (1.7 MB)

I’m using defold-input extention for dragging objects.

I can’t download on this PC but if you can find the on_input code, you need to add an if statement there limiting the X position. If you can find and share that code (copy and paste it here), I can have a look at it for you very quickly.

I will try one more attempt to solve this as you suggested. If I can’t then I will share code here.

boundary3
Thanks its working as expected. Did limited object X position as you suggested in its update funtion where I’m setting game object position.

1 Like

Well done! Unless you’re working with realistic physics, you don’t need collision objects.

2 Likes

If you ever need to drag physics simulated collision objects, then i find it best to drag a kinematic “handle” that has a joint connected to the object to be dragged. Sort of like a rubber band. Then if the user tries to drag the main object through a wall, it does not go through the wall.

I am new to defold though so maybe defold has a better way.

2 Likes