I'm right now testing a Lua script that involves using a CastMORay(). The function calls for these arguments:
CastMORay(SceneManager,const Vector,const Vector,number,number,boolean,number).
My script has all the arguments, expect for the second "const Vector". The console screams at me that I only have inputted a Vector.
Apparently, self.Pos is a "const Vector", but something like Vector(2,1) is just considered a Vector. So what is the difference between a const Vector and a Vector? How do I define one?
For those wondering, this script is meant to do a ray cast that is tangent to the projectile's (self) current trajectory every Update(). Keep in mind not all of my code is show (there isn't much else after it though). This is for detecting whether or not the projectile is about to collide with another movable object (the if statement for the distance between the projectile and the found object is not shown).
Code:
local horrizon = nil;
if self.Vel.X > 0 then
horrizon = 1;
elseif self.Vel.X < 0 then
horrizon = -1;
else
horrizon = 0;
end
local horVector = Vector(horrizon,0);
local velVec = Vector(self.Vel.X,self.Vel.Y);
local normal = velVec:Normalize();
local mag = math.sqrt(math.pow(self.Vel.X,2) + math.pow(self.Vel.Y,2));
local angle = math.acos( normal:Dot(horVector) / 1 ); --arccos( a*b/(|a||b|)). a and b always equal 1.
--angle is always returned positive, so we need to make sure whether or not the projectile is heading down or not.
if self.Vel.Y < 0 then
angle = angle * -1;
end
--debug
print("Horrizon Vector: (".. horrizon ..",0)");
print("Normal Vector: (".. normal.X ..",".. normal.Y ..")");
print("Magnitude: ".. mag);
print("Angle: ".. angle);
local targetID = SceneMan:CastMORay(self.Pos,normal,0,0,false,0); --normal will be tangent to the projectile's movement