Having some problems with ObstacleRays *SOLVED*
So yeah, i'm currently making a lightning gun. It works all fine, up until you start checking for collisions with anything. Here's how i'm doing the collision check, with irrelevant code cut out:
Code:
local checkVector = glow.Pos - oldPos;
if i > 1 then
local impactLength = SceneMan:CastObstacleRay(oldPos, checkVector, Vector(0, 0), endPos, glow.ID, 0, 0);
local trueLength = SceneMan:ShortestDistance(oldPos, endPos, true).Magnitude;
if trueLength < checkVector.Magnitude then
The values of glow.Pos and oldPos don't matter (i think, tell me if they do), the important part is that oldPos is the previous value of glow.Pos, so as to draw a vector in between those positions. The problem is that checkVector.Magnitude and trueLength almost always have different values, with trueLength usually being the smallest of the two. I'm pretty sure that they should give identical values unless the ray actually hits something that isn't air, yet it insists on exploding right in front of the unfortunate user. Any ideas on why this is happening? The deviations are usually quite small, but can be by as much as 1.
Edit: Also, another anomaly: trueLength is sometimes smaller than 3. Why is this odd? Well, because the next point is always at least 3 pixels away. Y'know, ♥♥♥♥ secrecy, here's the mod so far. Also,
pastebin for the lazy. Don't mind all the prints, it's just for checking. Any help would be greatly appreciated.
Edit2: Wait, minor cockup. Where it says "if trueLength < checkVector then" it should say "if trueLength < checkVector.Magnitude then".
EDIT 3: I figured it out. The problem? Apparently ObstacleRays are moderately retarded, so i did the following:
1. Cast MORay of desired length.
2. Use GetLastRayHitPos to determine impact point.
3. SceneMan:ShortestDistance the start and end points.
4. Glory.
Thread can be locked now, unless you want me to explain it better.