How do you give a turret a cone-shaped range?

I am making a pseudo tower defence game.
I have this tower, I want it to attack any enemy NPC if it’s within range.

I know I would use Cframes to rotate the turret to the face the NPC.

Raycasting is no problem.

Though I still do not know how I would make a range.

In this case, it’s a bit complicated, I’m trying to use Egomouses placement system and I also want the cone-shaped range to be displayed for the player to see when it is in placement mode.

Should I use an invisible cone-shaped part or something in front of the turret? and it will only show and glow when it is being placed? That is one solution I am considering though I find it a bit impractical.

I’m not looking for someone to script for me, I just want advice on what I use in order to overcome this problem.

You can use CFrame:PointToObjectSpace(Target’s position), it will use the orientation of the CFrame and return the a vector3 of the target as observed by the origin CFrame.

Basically, it returns how far the target is from where the CFrame is looking.

You can then use some trigo to derive the angle of the target from the normal and determine whether to activate the turret.

If you need clarification feel free.


Yep to add on here is an example of CFrame point to object space to measure the yaw angle and rotate a turret accordingly:

The turret should first aim at the enemy which fits the restricted yaw angle criteria and is closest to the turret which you can measure using magnitude between position of the enemy and turret.

Also for moving the turret with CFrames I made this, which should simplify the process.

1 Like

Thank you!
This seems like a great solution.
I’ll try something out and will ask if I run into something.

Thank you!
That resource seems extremely useful.
Thanks for sharing.