luskanek Posted January 7, 2016 Share Posted January 7, 2016 Hey everyone For more than a hour I've been trying to create a projectile which would fire at the opposite side of a vehicle (let's say I have an Infernus facing front, but I want for the projectile to shoot from the side to the car and not to the front (think of it as a pirate ship broadside cannon), or another explantation: Let's say my vehicle is facing North, but I want the projectile to be shot at West) local veh = getPedOccupiedVehicle(getLocalPlayer()) local x, y, z = getElementPosition(veh) local rX, rY, rZ = getElementRotation(veh) local x = x + 4 * math.sin(math.rad(rZ + 90)) local y = y + 4 * math.cos(math.rad(rZ + 90)) createProjectile(veh, 19, x + 3.5, y + 3.6) This is the base code I'm working with. I've tried to change the rotation and velocity of the projectile, which worked, however, only if the vehicle was facing a certain direction otherwise the projectile just destroyed the vehicle. Please, I'm been trying to do this for more than a hour and would be grateful if you could help me. Link to comment
Moderators IIYAMA Posted January 7, 2016 Moderators Share Posted January 7, 2016 use the first example of: getElementMatrix in order to take also the pitch in account. Can also be used to find the vector direction forwards of the vehicle, which you can add as velocity multiplier for your projectiles. Link to comment
vx89 Posted January 7, 2016 Share Posted January 7, 2016 btw, from wiki it seems that getElementRotation with no explicit rotation order return values for vehicles. as ZYX Link to comment
Revolt Posted January 7, 2016 Share Posted January 7, 2016 local orientation = -1 -- left is -1, right is 1 local veh = getPedOccupiedVehicle(getLocalPlayer()) local x, y, z = getElementPosition(veh) local _, _, r = getElementRotation(veh) x = x + 4 * math.cos(math.rad(r)) * orientation y = y + 4 * math.sin(math.rad(r)) * orientation createProjectile(veh, 19, x, y, z, 1, nil, 0, 0, 180 - 90 * orientation, math.cos(math.rad(r)) * orientation, math.sin(math.rad(r)) * orientation) Here. Link to comment
luskanek Posted January 8, 2016 Author Share Posted January 8, 2016 local orientation = -1 -- left is -1, right is 1 local veh = getPedOccupiedVehicle(getLocalPlayer()) local x, y, z = getElementPosition(veh) local _, _, r = getElementRotation(veh) x = x + 4 * math.cos(math.rad(r)) * orientation y = y + 4 * math.sin(math.rad(r)) * orientation createProjectile(veh, 19, x, y, z, 1, nil, 0, 0, 180 - 90 * orientation, math.cos(math.rad(r)) * orientation, math.sin(math.rad(r)) * orientation) Here. Great, thanks The projectile now shoots from the sides, however, another problem: If i shoot while my vehicle is facing north, everything is well, however, as soon as my vehicle is facing West, East or South, the projectile is fired, flies straight for a while and then it's trajectory changes and it changes the direction it flies to to the East, how do I fix? Link to comment
Revolt Posted January 8, 2016 Share Posted January 8, 2016 local orientation = -1 -- left is -1, right is 1 local veh = getPedOccupiedVehicle(getLocalPlayer()) local x, y, z = getElementPosition(veh) local _, _, r = getElementRotation(veh) x = x + 4 * math.cos(math.rad(r)) * orientation y = y + 4 * math.sin(math.rad(r)) * orientation createProjectile(veh, 19, x, y, z, 1, nil, 0, 0, 0, math.cos(math.rad(r)) * orientation, math.sin(math.rad(r)) * orientation) Maybe this'll work. Link to comment
luskanek Posted January 8, 2016 Author Share Posted January 8, 2016 Still does the same thing even If I'm facing north.. I've tried to use getElementMatrix, which worked too but the projectile would turn into the opposite direction it was flying and flew back. Then edited it a bit and the same happened as is happening now.. I hope there is a way Link to comment
Moderators IIYAMA Posted January 8, 2016 Moderators Share Posted January 8, 2016 I've tried to use getElementMatrix, which worked too but the projectile would turn into the opposite direction it was flying and flew back. That can be simply fixed by giving the opposite direction. 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