Nearest object example

user_avatar Made by: Hamed
hyperPad admin

PROJECT DESCRIPTION

Share this project:

In this example, we show how to find the object closest object to a label, and perform an operation to that object.

This shows off how to do a kind of multi pass loop when dealing with spawned objects. Everything is commented, but leave a comment if you have any questions or are confused by anything.

VERSION 1.0

Last Updated: September 21, 2022

COMMENTS

YOU MUST BE SIGNED IN TO LEAVE A COMMENT

July 04, 2016

Hamed, when you helped me with this and made this it helped me, but for some reason now in my game, I have the following but it won't work: Timer (0 sec.) - calculate distance - if (calculate distance is less than or equal to 5000) -behavior on I would have emailed for help but I just emailed something about an hour ago and didn't want to overflow them with comments, besides this example also kinda applies so I'm just gonna post it here. Thank you.

November 17, 2015

This is sweet...I've wanted to figure out how to do this for some game ideas...but never figured it out!!!!

November 17, 2015

Lol I managed to make 2 green circles 😝

November 17, 2015

I don't have it checking if two distances are the same. What you could do is add a very small random values to the calculate distance to ensure that two distances are never equal.

November 17, 2015

Pretty simple, and not really useful to me, but I guess it might help other people.

November 16, 2015

Thanks! But I am very confused on how to use "Behavior Bundle" "Recive Message" and "Broadcast message" and things like that. :(

November 16, 2015

What specifically are you confused about?

November 16, 2015

Well, everything. Most of my games don't use any of those behaviors. This I because I never really fully understood how to use them and what they were for.

November 16, 2015

I'm unsure of how to but the behaviors I listed before into use. I'm coming to realize that this really limits me. Things like values and storages confuse me.

November 16, 2015

Behaviour Bundle can serve two purposes. They are used to organize your behaviours and ensure the order of execution of connected behaviours. By using a Behaviour On, I can use it to tell my behaviour bundle to execute a group of behaviours without it being connected to anything. This lets me re-use the functionality of the behaviours connected to the behaviour bundle to not have to re-add the same behaviours over and over again.

In this case, I used the behaviour bundle to Calculate the distance, then get the label. I didn't want to have to keep adding those two behaviours over and over again when I could have it in one place.

Broadcast and Receive Message behaviours must be used together. The Broadcast Message behaviour notifies the scene that something happened. You can think of this as kind of a custom event trigger. Then the Receive message behaviour that is paired with the broadcast gets triggered as soon as the Broadcast gets triggered. In the case of this example, I'm using Broadcast to tell all my spawned objects to perform a calculation (First pass), then I Broadcast another message to tell all the Spawned objects to see if it was the nearest object (Second Pass).

Let me know if that cleared some stuff up for you.

November 16, 2015

Thanks a lot. It did clear a lot of things up, and I'm sure that using these behaviors will help me understand them even more. I knew that not using them limited me and I was doing more work than I needed to. This example and discription helped. :)