Force player to..
#1

Hey!

I'm building a system and i need to force the player to face an object,in order for the system
to be 100% usable.
That is the only thing i need to do,force the player face the object that he's doing something to it.
Reply
#2

pawn Код:
SetPlayerPos and SetPlayerAngle
I did not fully understand the question, please explain more.
Reply
#3

So i have an object already created.

When i'm pressing a key,the system starts to work,something happens,a robbery.
I need the player to be facing the object while that happens.
Reply
#4

Show us the code.
Reply
#5

I don't know why i have to post my code since i only need to know how can i force the player to face an object
Reply
#6

use trigonometry

pawn Код:
new Float:Ox,Float:Oy,Float:Oz,//objects coords
      Float:Px,Float:Py,Float:Pz,Float:Pangle;

GetPlayerPos(playerid,Px,Py,Pz);

new Float:Hypotenuse=GetPlayerDistanceFromPoint(playerid,Ox,Oy,Oz);
new Float:Adjacent=floatadd(floatabs(Ox),(float(Px)*(-1)));

Pangle=acos(Adjacent/Hypotenuse)*(-1);

SetPlayerFacingAngle(playerid,Pangle);
SetPlayerControllable(playerid,1);
i didnt test the code but somehow atleast should give u an idea
Reply
#7

Well, I've seen something like this. Maybe this could help you?
pawn Код:
stock SetPlayerFacingPlayer(playerid, facingid)
{
    new Float:Px, Float:Py, Float: Pa;
    new Float:x,Float:y,Float:z;
    GetPlayerPos(facingid,x,y,z);
    #pragma unused z
    GetPlayerPos(playerid, Px, Py, Pa);
    Pa = floatabs(atan((y-Py)/(x-Px)));
    if (x <= Px && y >= Py) Pa = floatsub(180, Pa);
    else if (x < Px && y < Py) Pa = floatadd(Pa, 180);
    else if (x >= Px && y <= Py) Pa = floatsub(360.0, Pa);
    Pa = floatsub(Pa, 90.0);
    if (Pa >= 360.0) Pa = floatsub(Pa, 360.0);
    return SetPlayerFacingAngle(playerid, Pa);
}
Source: https://sampforum.blast.hk/showthread.php?tid=69892
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)