Jump to content

Little Question to calculate coordinates from rotation


Maurize

Recommended Posts

Hey,

I need your help one time again.

Math is not my best so I hope someone of you can help me out.

I want to create peds, which "live" / "life" with animations, actions and so on.

First thing is, that I need to get them walking. So first steps are done...

I need to retrieve the coordinate 5 feet in front of my ped to get if line of sight is clear.

All i have is the x, y, z position and rotation from ped.

Is there a math code to get the 3 position coordinates in front of the ped?

Hoping for fast help.

Thanks!(:

  
setTimer( 
function() 
    local targets = getElementsByType( "ped" ) 
for i, target in ipairs( targets ) do 
    local px, py, pz = getElementPosition( target ) 
if ( isLineOfSightClear( px, py, pz, px + 1, py + 1, pz + 1 ) == true ) then 
    setPedControlState( target, "forwards", true ) 
    setPedControlState( target, "walk", true ) 
else 
    setElementRotation( target, 0, 0, math.random( 0, 360 ) ) 
    setPedControlState( target, "forwards", false ) 
    setPedControlState( target, "walk", false ) 
        end 
    end 
end, 1000, 0 ) 
  

Link to comment

Maybe this will help:

function getPositionInfrontOfElement(element, meters) 
    if not element or not isElement(element) then 
        return false 
    end 
    if not meters then 
        meters = 3 
    end 
    local posX, posY, posZ = getElementPosition(element) 
    local _, _, rotation = getElementRotation(element) 
    posX = posX - math.sin(math.rad(rotation)) * meters 
    posY = posY + math.cos(math.rad(rotation)) * meters 
    return posX, posY, posZ 
end 

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