Jump to content

Getting the X, Y and Z in front of vehicle


Deltanic

Recommended Posts

Hi, I'm searching a script to get the X, Y and Z in front of a vehicle. What I made until now, is only getting the X and Y in front of a vehicle, but it doesn't work. The object doesn't spawn.

if getElementData ( source, "spawnedRamp" ) then
destroyElement ( getElementData ( source, "spawnedRamp" ) )
setElementData ( source, "spawnedRamp", nil )
end
local rX, rY, rZ = getVehicleRotation ( getPedOccupiedVehicle ( source ) )
outputChatBox ( "DEBUG: Vehicle=" .. getElementModel ( getPedOccupiedVehicle ( source ) ) )
local pX, pY, pZ = getElementPosition ( etPedOccupiedVehicle ( source ) )
pX = pX + ( 10 * math.sin ( -rZ ) )
py = py + ( 10 * math.cos ( -rZ ) )
local rampObject = createObject ( 1655, pX, pY, pZ, rX, rY, rZ ) -- This object doesn't spawn. Or atleast, I can't see it.
setElementData ( source, "spawnedRamp", rampObject )

(Based out of this script of SA:MP's Pawn Language to get the X and Y points. I'm really not good in maths :$ )

new Float:a;
GetPlayerPos(playerid, x, y, a);
GetPlayerFacingAngle(playerid, a);
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));

But the problem is: I'm using my script in a Vehicle, and that object doesnt spawn. Problaby by a fault in the script. And I want to spawn that object in the air too, so I need the Z in front of the vehicle too.

Link to comment

Based on your vehicle speed too:

local theVehicle = getPedOccupiedVehicle ( source )
local speedx,speedy = getElementVelocity(theVehicle)
local px,py,pz = getElementPosition(theVehicle)
local nx,ny = speedx * 50 + px, speedy * 50 + py
if(math.abs(px-nx) > 1 or math.abs(py-ny) > 1) then
local a,b,r = getVehicleRotation ( theVehicle )
local newramp = createObject ( 1655, nx, ny, pz, 0, b, r )
end

..and you should use table for these, to avoid data syncing, if you don't need it to be synced with all clients:

something like

ramp[source][newramp] = newramp

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...