Separating objects

Hello!

I’m trying to create a system where if an object is placed upon an already occupied tile, it returns to its previous position.

Video Project 5 (1)

Though what I find is happening is this:

Video Project 5 (2)

Here is my code

Any ideas? Thanks!

The moment you drop the stick, both sticks (the one that was there initially and the one you dropped) satisfy the condition you have in this event, so both are moved.

Oh yeah, don’t get me wrong, I know why it’s happening, but I’m not sure on how to circumvent that.

I would probably do it like this:

  • add an object variable to the draggable objects, e.g. “index”
  • assign a unique index number to each object - you can run a an action at the start of the scene to assign each object a unique number (not sure how you create objects in the scene, so you might need to adapt this approach to your situation)
  • create a scene variable, e.g. PickedItem, and each time you pick an item, assign the index of that item to that scene variable
  • then add in that condition object.index = PickedItem

This way you only apply that action to that unique object instance

If you set the object variable to true when you start to drag it then you can repick it by checking if it’s true after the collision check. Just be sure to set it back to false afterwards.

IDK if you’re using the drag behavior or your own method but there’s also a cancellable drag behavior.

I’ve tried this to no avail. It just doesn’t work? I don’t know where I could’ve gone wrong.

Something like this?

Does it work? You might need to increase the distance value. Distance can’t be below 0.

I used collision but distance would also work. I put my objects into a group.

With a Variable

Without variable

Using the cancellable drag behavior

I’m using my own dragging system so that I can utilise some custom VFX. In my code, the “BeingDragged” variable controls literally whether the item is following the mouse or not. Do you know how I might adapt your code it fit mine?

The variable approach should work. Just make sure the variable is set to true and then back to false. Also, increase the distance check.

Later on, I can create an example without the drag behavior. If still needed.

Yeah, I created another version, using a new variable as a replacement for the “was just dropped condition” and it still didn’t work. I think I’ll need that example, sorry haha.

here exemple

immense thanks to keith. i didn’t know about this extenstion

Thanks for the help! I’m really sorry though, I’m using my own drag system because it’s more dynamic and easier to work with when it comes to the rest of the game. Thanks for trying anyway!

challenge accepted

This is what I might use.

I used the offset object variables bc I don’t like when an object jumps to the cursor position. I like the object to remain offset. For the tween time, I like to use distance divided by speed. That way it moves at a consistent speed regardless of the distance. It’s a personal choose and depends on the mechanics.

I would probably add a scene variable to track the dragging mode. Along with other checks.

I’ve set my code up to be pretty close to what you have now, and yet nothing happens when two draggables collide?

whats the difference between beingDragged and itemHeld? remove itemheld condition.

also remove mouse is in collision with draggable. as if an item is being dragged, it sure is touching the cursor.

also remove the first beingDragged condition. as the second time you check it in sub events, it doesn’t just pick but also filters (essentially its redundant)


cus i don’t think your action triggers at all.

try a log “cancel drag“ in console to see if it triggers

No, sorry, I realised that the way I had set up dropping beforehand was very silly and clashed with your system. That’s my bad.

Although, now I’m running into the problem where items will only drop how they are supposed to if they are in collision with each other. If you drop them normally, they just don’t tween to the position that they are supposed to.

this is a classic case of inverted collision problem:

(the inverted collision checks true for other objects)

i bring this issue for inverted collisions but in reality, this happens often when checking an inverted condition in general

It doesn’t let me drop items at all now so long as they are not in collision with another item.