Tails Posted August 16, 2012 Share Posted August 16, 2012 Oke , so what I want is to make the players vehicle shoot Objects on command. This works if I do x + 125 but this will always shoot the object into one direction, regardless of the vehicles rotation. So I tried to add the + 125 to the rX position instead but that didn't work, it just floats up a little bit. Any bit of help is appreciated. Part of my script: -- This will shoot the object 125 units from the X position of the players vehicle local x,y,z = getElementPosition(theVehicle) local rX,rY,rZ = getElementRotation(theVehicle) ball = createObject ( 1249, x, y, z +1, rX, rY, rZ) moveObject ( ball, 2500, x +125, y, z, rX, rY, rZ ) -- I assumed this would shoot the object 125 units relative to the vehicles rotation but that's not the case, it just floats about 2 inches up. local x,y,z = getElementPosition(theVehicle) local rX,rY,rZ = getElementRotation(theVehicle) ball = createObject ( 1249, x, y, z +1, rX, rY, rZ) moveObject ( ball, 2500, x, y, z, rX + 125, rY, rZ ) Tails Link to comment
cs8898 Posted August 16, 2012 Share Posted August 16, 2012 Hy had you tried to output all the variables? it coud be that there is a fail outputChatBox("foo|bar"..variable.."foo|bar") WFG cs8898 Link to comment
robhol Posted August 16, 2012 Share Posted August 16, 2012 Trigonometry. Xn = L cos(Rz), Yn = L sin(Rz) where the Xn and Yn are relative and must be added to your starting point, Rz is the Z rotation of the vehicle and L is the length of the vector. My maths might be a bit rusty, so someone will have to let me know if this is DEAD wrong. :3 Link to comment
Flaker Posted August 16, 2012 Share Posted August 16, 2012 This function return x & y coords in front of theElement function getPositionInFrontOfElement(theElement) local rotz = getPedRotation(theElement) local x,y,z = getElementPosition(theElement) x = x + ( math.cos ( math.rad ( rotz+90 ) ) * 1.2) y = y + ( math.sin ( math.rad ( rotz+90 ) ) * 1.2) return x, y end Link to comment
robhol Posted August 16, 2012 Share Posted August 16, 2012 This function return x & y coords in front of theElement function getPositionInFrontOfElement(theElement) local rotz = getPedRotation(theElement) local x,y,z = getElementPosition(theElement) x = x + ( math.cos ( math.rad ( rotz+90 ) ) * 1.2) y = y + ( math.sin ( math.rad ( rotz+90 ) ) * 1.2) return x, y end This looks more correct, I forgot about the radians and the +90° you need because GTA/MTA's rotations don't start at the "real zero". The 1.2 should probably be a parameter to the function instead of a hard-coded number. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now