I am making a projectile that homes in on players, and deals damage when the projectile gets close enough to a player. I don’t want to use .Touched do to its unreliability, but I am unsure how to create an event that does this.
I don’t really have any ideas of how to do this, besides perhaps having a secondary script that constantly checks and fire an event if it satisfies the condition, but that seems very inefficient.
You have a mechanism that makes the projectile home in on players right? Part of that must have something to calculate how close it is to a player, to find which one is the nearest. Just add another condition within that block, if the distance is below a certain point, you can call the function that does whatever you want to do, or just use a bindable event.
I have done (regrettably) very little with ray casting, so I am not very familiar with it. Could you explain how ray casting could check or detect if a humanoid was close enough?
My mechanism I have planned mainly consists of using a function that gets the nearest player and their distance, and using line force to move the projectile, and having the attachment on the player move to change targets. I think ill try this.
My current idea is that I could send raycasts out about every 0.5 seconds, propel the projectile in that direction, and if the distance is below something like 5 studs, it deals damage
On second thought, I likely wont need raycasts unless I wanted the projectile to home around barriers, which would also induce pathfinding. I think I can either just check the distance or use .Touched.
Would have to track the projectile position and the players root part position and do the magnatuned math for the trigger. To be viable you would need heartbeat updates, focused hard on them positions looping. Kind of the reason touch and hit boxes were created…
So, perhaps should I just create a box around the projectile and use .Touched?
I think my ray cast idea mentioned up there would be efficient, so ill try that first.
Now that I think about it, .Touched would likely just work more efficiently for this.
Note: Finished the homing projectile, and it works as expected. I basically just used a hitbox around the projectile, when something hits it with .Touched, it deals damage and moves to the next target. This is done with lineforce, and the target change is done simply by moving the second attachment and reducing the projectile velocity. The homing is kind of crude, but its all I needed, so it works.