Get collision target

Hi everyone.

I have an object named Ball with draggable behavior, and I want to know on which target is dropped, to access that target dynamically.

I tried making an object group “Targets”, testing if Ball collides with it and showing Targets.ObjectName(), but doesn’t work.

Any ideas?

Welcome ExGaul,

IDK if this is still an issue. Make sure your object group has all of the target objects in it.

The top event will show the name of target object but only if there’s 1 object. It will still trigger if there are multiple collisions but it will only show 1 object name.

The bottom event uses for each object. It will display the name of multiple objects.

Thanks, Keith_1357…

It doesn’t seems be what I want, but I’ll try it.
I want it for make an code optimization… I want to store the target’s name in an object variable, and check if Ball’s drop target is the same of the stored one.

IDK if am I clear…

Gotcha. ObjectName() is currently an expression. I’ve suggested in the past that they make it a condition as well.

https://forum.gdevelop.io/t/add-objectname-as-an-object-condition/58637?u=keith_1357

What is your goal? What are you trying to do. A little more context could help.

The problem is that using compare 2 strings would check if an object was name something but it wouldn’t pick the objects. It only evaluates as true or false and triggers the action or the next conditon if true. The same would apply to comparing a scene variable to the object name.

My examples use cursor is on object bc it’s easier for me to test. I use the action to rotate the angle bc that’s a very visual way to tell if an action is triggered.

These don’t really work with multiple objects. If there was only 1 object collision at a time this would work. They say the same thing just from a different direction and condition.

I thought you would be able to use a for each object but that doesn’t work either because there’s still no filtering and it still applies it to all selected objects.

I think the easiest way would be with an object variable. It’s a bit of a work around. When you use an object variable condition, it evaluates to true/false but it also picks the matching objects.

You could use an ID or the object name. An ID might be needed if you’re targeting a particular instance not an object.

Honestly, it depends on what you’re doing. You could also just use an object variable named Target and set it to true for the targeted object and check if the group object variable equals true. Linking is another option.

Yep, this is closer what I want!!!

Let me try it, otherwise I’ll try to explain more what I want, and show some code…

Thx a lot!!

1 Like