Jump to content

Getting a ped to follow me


TwicH

Recommended Posts

Hello guys, I'm just starting to learn to script and I've been stuck on this issue for a while now

  
local x,y,z = getElementPosition (localPlayer) 
local zombie = createPed (20,x+math.random(-4,4),y+math.random(-4,4),z) 
  
function follow() 
    x,y,z = getElementPosition (localPlayer) 
    zpx,zpy,zpz = getElementPosition (zombie) 
     
     
    local a = zpx - x 
    local b = y - zpy 
    local c = a*a + b*b 
     
    local sinlaw = 90/math.sin(b) 
    local zangel = math.sin(a)*sinlaw 
     
  
    setPedCameraRotation (zombie,zangel) 
     
     
    setPedControlState(zombie, "forwards", true) 
end 
  
setTimer ( follow, 500, 0) 
  

the code made sense the first time that I wrote it and since then I've just messed with a few variables without really thinking hoping that it would bring me an easy solution. also please don't ask me why I did the math the way I did, I'm very bad at it and that's what I came up with.

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