Hello Bartje,
I understand that you want to simulate shooting a rocket launcher in the direction of the player's view/camera/where-he-is-looking-at. I assume that you want to have the definition of the line starting from the camera position going in the direction of the camera's front vector. This is actually not as difficult as you might think. Here is some code as an idea.
client.Lua
-- Calculate the direction vector.
local csx, csy, csz, ctx, cty, ctz = getCameraMatrix();
local cdir = Vector3(ctx - csx, cty - csy, ctz - csz);
cdir:normalize();
-- The line starts of (csx, csy, csz) and the direction vector is cdir.
-- You can now interpolate on this line using setElementPosition and the following function.
local function interpolate_position(px, py, pz, dir, timeSpeed)
return
px + dir.x * timeSpeed,
py + dir.y * timeSpeed,
pz + dir.z * timeSpeed;
end
-- An example?
local obj = createObject(1454, csx, csy, csz);
local moveStart = getTickCount();
addEventHandler("onClientRender", root, function()
local curTime = getTickCount();
local elapsedTime = ( curTime - moveStart );
local timeSeconds = elapsedTime / 1000;
setElementPosition(obj, interpolate_position(csx, csy, csz, cdir, timeSeconds));
end
);
(code not tested)
Explanation: the direction is defined as the normal vector of the difference between two 3D points. You can subtract the start 3D vector from the target 3D vector to get the difference between two 3D points.
Of course, if you want to keep multiple objects flying in certain directions you must remember their starting positions and their direction vectors along with the MTA object handle. Should be a good exercise with the boiler-plate code above.
You have mentioned the moveObject function. Your feeling may be correct because that function does specify fixed timelimit for object flight whereas above code does allow for indefinite length of object flight.
- Martin