hello, ive been making sentry gun for my game, but there’s issue
i need to actually find can turret see enemy before shooting in they direction
so i used workspace:raycast() method. but it ALWAYS returns nil. FindPartOnRay() too.
sentry uses OOP module to control it
Why would he need to normalise the vector? The direction of a vector doesn’t depend on its magnitude.
You’re right about the RaycastParams thing and the lookat variable.
If a vector is not normalised, it can sometimes cause anomalies and distance issues.
Unit normalises the magnitude to 1, so you can then multiply by the distance, e.g 100, if the starting value is not 1, it might overshoot or undershoot the distance. Causing unreliable results.
It’s just good practice imo. I usually use lookvectors or something like this:
Change the direction variable to this local direction = ((workspace.sentry.Model.PrimaryPart.CFrame.LookVector * self._ai.look_distance) - self.position).Unit * self._ai.max_distance
It’s necessary only when working on magnitudes, but for obvious reasons. When determining the position of a particle, (3,2) isn’t the same as (6, 4). The same goes for magnitudes of velocities, that’ll be different.
For vectors utilised only for determining the direction that’s always possible, instead. Those 2 vectors would be perfectly fine, both, since when calculating the direction of a vecgtor you can’t NOT normalise, as you should be calculating the angle at which something is shot. That implies calculating the ratio between the x and y components, meaning that it’d remain just the cos and sin of the angle, without any reference to the magnitude.
But again, this is NOT a matter of distance, nor consistency. If one uses the look vector there is no issue. If we’re using 2 position vectors to determine the direction it’s easier to do so, since the calculations done by the engine are always the same (when you raycast the engine is gonna have to do angle calculations, the same as normalisation; instead of doing them twice let the engine do them once). Instead of adding extra code and making it harder to read (well, not even that much tbf, a .unit won’t give too many head aches) let’s keep it simple.
I don’t see how a false positive could ever be returned.