Making A Radar/Proximity Sensor

Like I wanted to use raycasting to make some type of 180º proximity sensor but it was so hard to do. Like the raycast didn’t even detect the parts it needed to detect.

I already deleted the script but like it was also really innefficient.

What should I do instead if I want to make some type of radar or proximity sensor?

Someone told me to use :Dot.

1 Like

Well, if you aren’t concerned with it being a radius, then you could always make a region3 in front of the sensor extending out a certain range in front of it. Otherwise, your best option might just be spawning rays 180 degrees around the front of the sensor like you were trying to do.

1 Like

thing is that spawning rays 180 degrees

also region 3 is rectangular… But i guess I’ll give that a try anyway.

1 Like

Maybe you can create an invisible circular part around the sensor and use .Touched and :GetTouchingParts() to determine the parts in the radius.

1 Like

Someone told me that’s highly inefficient and it’ll cause so much lag cause too many touch events will be firing. You gotta understand that another car in my game has like 88 baseparts in the model itself.

1 Like

Are you gonna be constantly moving the sensor? Also raycasting like that should be as inefficient.

1 Like

The sensor is going to be in movement along with the car.

1 Like

As far as I know, that is the only way to achieve this. I will definitely try figuring out a more efficient way.
Have you tried that method though?
If you haven’t, there’s no harm in trying.

1 Like

use .magnitude to detect if someone/something is inside the radius :grin:

2 Likes

In that case, wouldn’t it be required to keep track of everything that can come inside the radius

1 Like

kk thanks. I’ll consider region 3 and magnitude next time i make an AI turret.

1 Like

ummmm… no?.. trying to roast on someone elses post will not make your more efficient :man_shrugging:

1 Like

Why don’t you try :GetTouchingParts() but only check like every 0.5 s or so to prevent touch events firing.

1 Like

I’m sorry, that was not my intention. But could you explain how that would work?

1 Like

I think you are looking for something like this example I found a while back.

You know the positions for the player and the detector. At the moment, I’m not too sure how to fully implement the picture. It’s been a while but it does use trigonometry. Hopefully this helps a bit, maybe someone can add to this.

In my game proximity triggers work by having a position as the center, and a part to listen for. It then takes the (PartPositionVector - CenterPositionVector).magnitude to determine the distance the part is. After that, it will just determine whether they’re within reasonable range (20 studs for instance). I think this is more effective than raycasting, if you are trying to do what I think you are trying to do. Rays would probably be more appropriate if you needed to determine the direction the player was coming from or something.

3 Likes

If you want a scan-like action like real life radars do, use a hingeconstraint and a script to make the part oscillate left to right. (Suggestion) in a limit, for example -45 to 45 degrees