Jump to content

Check if player is facing player


Wisin

Recommended Posts

  • Moderators
Hi, I was wondering if anyone could help me with making a function to check if a player is facing another, I got told to use findRotation useful function, but I don't know what to check exactly.

Thanks.

Where do you need it client or server side?

Which will be the main filter of the functions you can use and can't use. :idea:

Link to comment

I need it client side, this is what I tried:

local sx, sy = guiGetScreenSize ( ) 
local tx, ty, tz = getWorldFromScreenPosition ( sx / 2, sy / 2, 7 ) 
local px, py, pz = getCameraMatrix ( ) 
local hit, _, _, _, elementHit = processLineOfSight ( px, py, pz, tx, ty, tz, true, true, true, true, true, false, false, false, localPlayer ) 
if ( hit and isElement ( elementHit ) and getElementType ( elementHit ) == "player" ) then 
    local px, py, pz = getElementPosition ( elementHit ) 
    outputChatBox ( "hit: ".. tostring ( getPlayerName ( elementHit ) ) ) 
end 

The problem is that it hardly detects it, plus, I don't want it to be camera based, since I could just turn around and look at a player and it would return it.

Link to comment

So just use the peds position + calculate the position in a certain distance infront of it.

Im pretty sure there already is some function on the wiki to do this,

since its used on shooter maps to make projectiles fly the right direction.

But its not that hard anyway.

Then use processLineOfSight on these two positions and it always should check whats in the peds view.

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