Jump to content

Projectile direction problem


Sasu

Recommended Posts

Hi all!

I'm trying to do a shooter script but I have a problem with the projectile direction:

22aff3eb8368e977759e748281c0de73o.png

function ejectProjectile() 
    local localVehicle = getPedOccupiedVehicle(source) 
    local ax, ay, az = getElementPosition(source) 
    local x,y,z = getPositionFromElementOffset(localVehicle,0,5,0) 
    local _, _, rz = getElementRotation(localVehicle) 
    local vx, vy = x - ax, y - ay 
    createProjectile(source, 19, x, y, z, 100, nil, 0, 0, 180 - rz, vx/3, vy/3, 0) -- I take velocity math here: viewtopic.php?p=357503#p357503 
end 

The problem is that the projectile goes right(red arrow) and not straight(blue arrow) where it should go. I'm not good in math so if anybody can help me I will be very grateful :roll:. Thank you very much.

Link to comment

You can just do this and it will automatically shoot forwards, and it wont collide with your vehicle either.

function ejectProjectile() 
    local vehicle = getPedOccupiedVehicle(source) 
    if(vehicle)then 
        local x, y, z = getElementPosition(vehicle) 
        createProjectile(vehicle, 19, x, y, z) 
    end 
end 

I edited the wiki page for createProjectile for others that need it as well.

Edited by Guest
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...