How do I do a scanner [SOLVED]

Hello everyone.

I’m working on a space game where you play a Mining robot. You have a scanner and here’s the deal : I want to create kind of a radar.

The idea is :

  • You press a button
  • The scanner look for close objects (within a range of 1000 pixels), like asteroids, ennemies, Safe spots
  • Some marks pops up around the droid, pointing the nearest objects, then, slowly disappear.

I don’t know if It’s very clear, but I keep losing in my attempts to create the marks toward ALL the near objects. Only one shows up each time I try.

Any kind of help would be very helpful !

1 Like

What I would do is pick a random object every X second, this is to avoid checking distance for too many objects at once.
If distance is <= 1000 then check if the object has any link to a mark using the object linking events.
if the object has no link to any mark then create a mark and link the mark to the object.
Then if you want the mark to point toward the object, just pick the object the mark linked to and set angle toward the position of the object. for each mark.

To remove a mark, pick a random mark and pick the object it is linked to and check if object distance is still <= 1000. If it not, the distance is > 1000 then delete the link between the object and the mark and delete the mark.
The reason I would pick a random mark again is that to avoid checking distance for too many objects at the same time.

If you never used object linking before maybe it is not 100% clear to you, so if you don’t really understand what I’m talking about I recommend to play with object linking events a little and then come back to this.

1 Like

Tank you for the reply ! It’s really helping me.
I’m starting with linked objects, so I may have made some mistakes but now, I have something which is close to work, I have the marks, they rotate toward the right position but they all rotate toward the same object, I don’t understand why. Here is my lines of code :

(inverted) Take all linked objects linked to marks
Trigger once

  • create a mark
  • link mark and obkects
  • reset timer

I only use the timer as a checker like you said, so I don’t think that’s the point of the error

this is the condition

  • this is the action

There is a number of things that could go wrong here. Could you please show me a screenshot of your events. What I’m interested in particular is:

  1. The events where you check distance between the robot and objects and create the marks and link them to the objects
  2. The events where you rotate the marks toward the objects they are linked to
  3. The events where you remove the marks that no longer needed either because the object is too far away or you have destroyed/mined the object and the object no longer exist maybe.

If necessary upload 3 screenshots showing the events for these 3 things only.


Here you go, Hope you can understand. I add a for each condition, but again, doesn’t work.
The “sonar” object is a simple visual effect, btw. “Objgrav” stands for “Objects with gravity”, wich is the kind of objects the sonar must show. It’s an object group.
oh, and marqueur = mark

I didn’t add the destroy functionnality. First, I want the sonar working lmao

Few things.
You are using the timer inside the for each event which means you are going to skip a few objects. This is not exactly what I was suggesting, anyhow for now just remove the timer since you loop through every single object and check distance with every single one of them anyway and keep the for each event and don’t worry about performance and timer for now.

Then I was suggesting to pick a random mark but you don’t do that and you don’t even use a for each loop. So what you want to do is either pick a random mark then pick the object the mark linked to then rotate mark toward the object it is linked to or use a for each loop for the marks the same as with the objects.

For each loop should solve the problem, but depends on how many objects you have in the scene it can hit performance hard, you want to be careful with that.
In case you got it working with for each object event, but you having problems with performance, just remember that your game runs at 30-60 frames / second which means each calculations you make is executed that many times for every single object but usually it is not necessary.
So if you ever have a performance problem, what I suggesting is picking a random object instead of using for each loop (which runs 60 times a second so you pick 60 random objects in 1 second which is usually enough depends on how fast paced your game is) and may even use a timer before picking the random object to further reduce the number of calls you make / second.

But for now, just use raw for each loop to get it working so you don’t get confused and worry about performance after if you get any problems with performance at all.

Yeah sorry for showing that I’m not listening you, I posted the same topic in the FR forum and they ask me to use an “for each” loop. But I tried your way of work, and the results -out of performances- are the same. With one target, it’s working very well, but with more targets, it’s still don’t work.
Seems like the link objects aren’t take in account and the programm keep re-link them, pointing the same objects, even with several marks.

So, how do you do to say “rotate toward your link object” ? I try many things, any of them seems to work

Thank you for your help, I solved it ! It’s really cool-looking and working now, aha !
I’m so happy, thanks :blush:

Here is the code !

Now I’ll just add the distance scanner, optimisation of the whole thing, and I’m done !
Thanks again.