Jump to content

Reach destination and stop


MooShalaby

Recommended Posts

hello guys , I'm trying to move a ped from a place to another, and when ped reach the specified destination, ped stop and outputChatBox say "You have reached your destination"

code is work but if not working where's the problem 

function findRotation( x1, y1, x2, y2 ) 
    local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) )
    return t < 0 and t + 360 or t
end

function makePed()
    local thePed = createPed(56, 2023.2751464844, 1544.3005371094, 10.820962905884)
setPedAnimation(thePed, "ped", "WOMAN_walknorm")

local x, y, z = 2024.2377929688,1543.8177490234,10.819551467896
local tx, ty, tz = 2030.9291992188,1544.3975830078,10.8203125

setPedRotation(thePed, findRotation(x, y, tx, ty))
local pedX ,pedY ,pedZ = getElementPosition(thePed)

if getDistanceBetweenPoints3D(pedX ,pedY ,pedZ , tx, ty, tz) <=0.1 then 
    setPedAnimation(thePed,false)
    outputChatBox ("You have reached your destination")
    end


end
addCommandHandler("ped", makePed) 

 

Link to comment
createPed
createColCircle
setElementRotation --setPedRotation is deprecated.
setPedWalkingStyle
setPedControlState --Use walk and forwards as control names.(give true as value)

isElementWithinColShape
setPedControlState --ped is in circle col and this value will be false (stop ped)
outputChatBox --If you want a message visible to everyone, trigger it from the server side.

addCommandHandler --create command event

 

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