Jump to content

Camera target set to ped


Artisz

Recommended Posts

Hi!

How can I do that when I click on a ped(there are more ped, where can we talk with them), and after click, set the camera on him, so we can look at him. I create a ped, in x,y,z, and where I need put the camera that I can see the ped front?

Sorry for my English!

Link to comment

Use

 addEventHandler ( "onClientClick", getRootElement(), clickOnPed) 

https://wiki.multitheftauto.com/wiki/OnClientClick to get the element and check if it's a ped using

getElementType 

and then use

setCameraTarget 

to set the camera target on the ped

like

function resourceStart() 
  addEventHandler("onClientClick", getRootElement(), clickOnPed) 
end 
addEventHandler("onClientResourceStart", getRootElement(), resourceStart) 
  
function clickOnPed(button, state, x, y, z, worldX, worldY, worldZ, clickedWorld) 
  if (button == "left" and state == "up") then 
    if getElementType(clickedWorld) == "ped" then 
      setCameraTarget(ped) 
    end 
  end 
end 

Link to comment

It's don't working. I create a ped: thePed = createPed(120, 1053.97461, 2096.96313, 10.82031)

And I set the camera target: setCameraTarget (thePed)

But nothing. And with the CameraTarget we can move the camera, no? I want to freeze the camera, that we can see the ped front side.

Link to comment

Should work with every ped

function getPositionFromElementOffset(element,offX,offY,offZ) 
    local m = getElementMatrix ( element ) 
    local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] 
    local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] 
    local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] 
    return x, y, z 
end 
  
function resourceStart() 
  addEventHandler("onClientClick", getRootElement(), clickOnPed) 
  thePed = createPed(120, 1053.97461, 2096.96313, 10.82031) 
end 
addEventHandler("onClientResourceStart", getRootElement(), resourceStart) 
  
function clickOnPed(button, state, x, y, z, worldX, worldY, worldZ, clickedWorld) 
  if (button == "left" and state == "up") then 
    if getElementType(clickedWorld) == "ped" then 
      local pedX, pedY, pedZ = getElementPosition(clickedWorld) 
      local x, y, z = getPositionFromElementOffset(clickedWorld, 0, 3, 0) 
      setCameraMatrix(x, y, z, pedX, pedY, pedZ) 
    end 
  end 
end 

Link to comment

I copy your code, but It's still don't working. I put messages the code, and what is under these lines:

local pedX, pedY, pedZ = getElementPosition(clickedWorld) 
      local x, y, z = getPositionFromElementOffset(clickedWorld, 0, 3, 0) 
      setCameraMatrix(x, y, z, pedX, pedY, pedZ) 

Dont working.

Link to comment

Sorry, forgot arguments of onClientClick

function getPositionFromElementOffset(element,offX,offY,offZ) 
    local m = getElementMatrix ( element ) 
    local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] 
    local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] 
    local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] 
    return x, y, z 
end 
  
function resourceStart() 
  addEventHandler("onClientClick", getRootElement(), clickOnPed) 
  thePed = createPed(120, 1053.97461, 2096.96313, 10.82031) 
end 
addEventHandler("onClientResourceStart", getRootElement(), resourceStart) 
  
function clickOnPed(button, state, x, y, worldX, worldY, worldZ, clickedWorld) 
  if (button == "left" and state == "up") then 
    if clickedWorld and getElementType(clickedWorld) == "ped" then 
      local pedX, pedY, pedZ = getElementPosition(clickedWorld) 
      local x, y, z = getPositionFromElementOffset(clickedWorld, 0, 3, 0) 
      setCameraMatrix(x, y, z, pedX, pedY, pedZ) 
    end 
  end 
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...