DjSt3rios Posted June 21, 2011 Share Posted June 21, 2011 (edited) Hello, I have a problem. Im making a map, and i used this code: local occupiedVehicle = getPedOccupiedVehicle(getLocalPlayer()) local x, y, z = getElementPosition(occupiedVehicle) local vx, vy, vz = getElementVelocity(occupiedVehicle) local rotx, roty, rotz = getElementRotation(occupiedVehicle) createProjectile(getLocalPlayer(), 19, x, y, z, 500, nil, 0, 0, rotz, vx, vy, vz) But its not going as i want... i want to make it read the rotation of the car, and make the bullet go straight where the car looks. Also its not synchronised, in my friend's screen it goes to opposite direction any help? Edited June 22, 2011 by Guest Link to comment
Wojak Posted June 22, 2011 Share Posted June 22, 2011 I don't think that getElementRotation(occupiedVehicle) will return the rotations with x,y,z order, try different configurations (y,x,z or z,x,y), also you only setting the z rotation on the Projectile, you should set all 3 components. Also make sure that the projectal is created only on one client at the time (projectal is the only type of element that will exist on all clients even created on one) Link to comment
DjSt3rios Posted June 22, 2011 Author Share Posted June 22, 2011 Still no luck Thats my current code: local x, y, z = getElementPosition(occupiedVehicle) local vx, vy, vz = getElementVelocity(occupiedVehicle) local rotx, roty, rotz = getElementRotation(occupiedVehicle) createProjectile(getLocalPlayer(), 19, x, y+2, z+2, 1.0, nil, rotx, roty, rotz, vx, vy, vz) I also tried to change 'nil' which is the target(althought i think it only works with ID 20, which is heat seeking), to rotz, but nothing changed Link to comment
CowTurbo Posted June 22, 2011 Share Posted June 22, 2011 try to change nil to getRootElement() Link to comment
Wojak Posted June 22, 2011 Share Posted June 22, 2011 @CowTurbo do you even know what is a rootElement? @DjSt3rios as I said the order of vehicle rotation components are inverted... also I wrongly assumed that you know what you setting the vehicle velocity as projectile velocity... this code will calculate a correct vector direction (at lest it should) local occupiedVehicle = getPedOccupiedVehicle(getLocalPlayer()) local x, y, z = getElementPosition(occupiedVehicle) local matrix = getElementMatrix(occupiedVehicle) local offX = 0 * matrix[1][1] + 1 * matrix[2][1] + 0 * matrix[3][1] + 1 * matrix[4][1] local offY = 0 * matrix[1][2] + 1 * matrix[2][2] + 0 * matrix[3][2] + 1 * matrix[4][2] local offZ = 0 * matrix[1][3] + 1 * matrix[2][3] + 0 * matrix[3][3] + 1 * matrix[4][3] vx = offX– x vy = offY – y vz = offZ - z local rotx, roty, rotz = getElementRotation(occupiedVehicle) -- experiment with rotx, roty, rotz order createProjectile(getLocalPlayer(), 19, x, y, z, 500, nil, 0, 0, rotz, vx, vy, vz) Link to comment
DjSt3rios Posted June 22, 2011 Author Share Posted June 22, 2011 Ok i finally made it quite well, not perfect though but its enough good. Thanks for your help. Edit: oh i didnt see ur previous message buddy, i will reply soon with new answers. Link to comment
DjSt3rios Posted June 22, 2011 Author Share Posted June 22, 2011 With this code, the script doesnt work at all, i tried using debug, and its not working at all. I also tried to fix it without luck. EDIT: I made it working, but still no luck Link to comment
Wojak Posted June 22, 2011 Share Posted June 22, 2011 addCommandHandler("boom",function() local occupiedVehicle = getPedOccupiedVehicle(getLocalPlayer()) local x, y, z = getElementPosition(occupiedVehicle) local matrix = getElementMatrix(occupiedVehicle) local offX = 0 * matrix[1][1] + 1 * matrix[2][1] + 0 * matrix[3][1] + 1 * matrix[4][1] local offY = 0 * matrix[1][2] + 1 * matrix[2][2] + 0 * matrix[3][2] + 1 * matrix[4][2] local offZ = 0 * matrix[1][3] + 1 * matrix[2][3] + 0 * matrix[3][3] + 1 * matrix[4][3] vx = offX - x vy = offY - y vz = offZ - z local rotx, roty, rotz = getElementRotation(occupiedVehicle) createProjectile(getLocalPlayer(), 19, x, y, z+1, 500, nil, 0, 0, 360 - rotz, vx, vy, vz) end) tested in game, and works Link to comment
DjSt3rios Posted June 22, 2011 Author Share Posted June 22, 2011 It works, Thank you! Edit: I got a small problem if you can help with, I want to create the bullet in front of the car and go straight. I made something, but if i turn like 90 degrees it is not working properly. I made it like this: createProjectile(getLocalPlayer(), 19, x, y-2.3, z+0.5, 5000, nil, 0, 0, 360 - rotz, vx, vy, vz) But sometimes x might need to be changed. Maybe i can fix it somehow? Link to comment
Wojak Posted June 23, 2011 Share Posted June 23, 2011 createProjectile(getLocalPlayer(), 19, offX, offY, offZ+0.5, 5000, nil, 0, 0, 360 - rotz, vx, vy, vz) this should do it, but if the vehicle is too long, you will need to calculate a larger ofset (this code should create the rocket 1m in front of the vehicle center of mass) Link to comment
DjSt3rios Posted June 23, 2011 Author Share Posted June 23, 2011 Well with this it increases the height of the bullet EDIT: I did some modifications and works, thanks anyway 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