Jump to content

Point at player


cokacola

Recommended Posts

Hey guys, can't seem to think of how to do this(probably simple) but I am creating a couple jets that will follow a player after they fly over the restricted area, and I can't seem to think of how to determain what direction the ped needs to turn the plane(left or right) to point the plane in the direction of the player.

Any ideas?

EDIT:

If you could give me a couple pointers on not having them manage to fly down into the ground, that would be helpful too(I want them to keep the altitude they started at).

Thing is, I don't want to set the rotation, I want to actually use the set control thing so the ped properly flies(otherwise it looks rather weird), so I need to know whether to make them fly up, down, left or right.

EDIT 2:

Here is the full code if you want to see what I have so far:

  
local Rzone1 = createColSphere(175.84280, 1889.23828,1, 200.0) 
--createMarker ( 175.84280, 1889.23828, 22.4141, "cylinder", 100.0) 
  
function planeFly(ped,plane,target) 
    if(ped and plane and target) then 
        local tx,ty,tz = getElementPosition(target) 
        local px,py,pz = getElementPosition(plane) 
        local rx,ry,rz = getElementRotation(plane) 
        --local px,py = findRotation(px,py,tx,ty) 
         
        --if(rx > px) then 
        --   
        --elseif(rx < px) then 
        --   
        --end 
        setPedControlState(plane,"forwards",true) 
         
        local rrx,rry,rrz = findRotation(px,py,tx,ty) 
        if(rrx == nil) then rrx = 0 end 
        if(rry == nil) then rry = 0 end 
         
        if(rrx > 1) then 
            rrz = -20 
        elseif(rrx < 0) then 
            rrz = 20 
        else 
            rrz = 0 
        end 
         
        setElementRotation(plane,rrx,rry,rrz) --TEMPORARY! I want to make the vehicle drive properly! 
         
        if(getDistanceBetweenPoints2D(px,py,tx,ty) < 100) then 
            local bom = createProjectile(getLocalPlayer(), 20, (px+10), (py+5), (pz-10), 10.0, target ) 
        end 
         
        setTimer(planeFly,500,1,ped,plane,target) 
    end 
     
     
    -- 
end 
  
function makePlanes(target) 
    local v1 = createVehicle(520,358.43,2038.49,335.4141) 
    local v2 = createVehicle(520,308.43,2138.49,335.4141) 
     
    local p1 = createPed(287,0,0,0) 
    local p2 = createPed(287,0,0,0) 
     
    warpPedIntoVehicle(p1,v1) 
    warpPedIntoVehicle(p2,v2) 
     
    setPedControlState(p1,"special_control_up",true) 
    setPedControlState(p2,"special_control_up",true) 
    --setTimer(setPedControlState,5000,1,p1,"special_control_uo",false) 
    --setTimer(setPedControlState,5000,1,p2,"special_control_down",false) 
    planeFly(p1,v1,target) 
    planeFly(p2,v2,target) 
end 
function boemRadius(player, a) 
    local x,y,z = getElementPosition(player) 
    if (z >= 30) then 
        local target = getPedOccupiedVehicle(player) 
        if(target) then 
            if(getVehicleType(target) == "Plane" or getVehicleType(target) == "Helicopter") then 
                --[[local x,y,z = math.random(354.43,358.43),math.random(2028.49,2038.49),math.random(28.4141,35.4141) 
                 
                local bom = createProjectile(getLocalPlayer(), 20, x, y, z, 10.0, target ) 
                setTimer( boemRadius, 2000, 1, player )]]-- 
                setTimer(makePlanes,math.random(1000,5000),1,target) 
                 
            end 
        end 
    end 
 end 
addEventHandler("onClientColShapeHit", Rzone1, boemRadius) 
  
  
function findRotation(x1,y1,x2,y2) 
  
  local t = -math.deg(math.atan2(x2-x1,y2-y1)) 
  if t < 0 then t = t + 360 end; 
  return t; 
  
end 
  

(All in a clientside file)

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...