Spawn something relative to the player.
#1

Hey there.

Could someone explain to me how to spawn something in front of the player, or behind, or on the side, etc.?

Adding to the players coordinates is not what I'm looking for. I want the thing spawned to spawn in front of the players view, like, 10.0 units away in the players facing direction.

It's probably some shitty cos/sin-shit formula that I can't even be bothered to figure out myself, so if someone would enlighten me here, thanks.
Reply
#2

you mean some thing like?
pawn Код:
stock Float:GetPosInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance){
    new Float:a;
    GetPlayerPos(playerid, x, y, a);
    if (IsPlayerInAnyVehicle(playerid)) GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    else GetPlayerFacingAngle(playerid, a);
    x += (distance * floatsin(-a, degrees));
    y += (distance * floatcos(-a, degrees));
    return a;
}
Reply
#3

Probably, gonna test it.

So how does that stock work?

GetPositionInFrontOfPlayer(players x, players y, distance I want in front of player)?

And why is there no z?

Explain please.
Reply
#4

Quote:
Originally Posted by IcyBlight
Probably, gonna test it.

So how does that stock work?

GetPositionInFrontOfPlayer(players x, players y, distance I want in front of player)?

And why is there no z?

Explain please.
Because you would add the z when you spawn it.
Reply
#5

Alright so what does this return, exactly?

Confusing code, to me at least.

I assume it returns X and Y coordinates in the players facing direction, with a distance to the player as the one specified?

Like, returns "352.1234,1245.4321"? Or what?
Reply
#6

Very briefly,
GetPositionInFrontOfPlayer(playerid,&Float:X, &Float:Y, distance)

&Float:X is the variable you want to STORE the X coord in
&Float:Y is the variable you want to STORE the Y coord in

You do not need returns
Reply
#7

Quote:
Originally Posted by jonrb
Very briefly,
GetPositionInFrontOfPlayer(playerid,&Float:X, &Float:Y, distance)

&Float:X is the variable you want to STORE the X coord in
&Float:Y is the variable you want to STORE the Y coord in

You do not need returns
So, basicly, like;

pawn Код:
new Float:frontx, Float:fronty, Float:pz, Float:pangle;

GetPositionInFrontOfPlayer(playerid, frontx, fronty, 30.0) // If I want the position 30 units in front of the player

GetPlayerFacingAngle(playerid, pangle);

GetPlayerPos(playerid, 0, 0, pz); // Dno if I need -1 instead of 0 here. I don't need the X and Y, just the Z.

CreateVehicle(560, frontx, fronty, pz, pangle, 1, 1, -1);
This would create a white sultan 30 units in front of me? Correct?
Reply
#8

Try it, but it should
Reply
#9

Quote:
Originally Posted by jonrb
Try it, but it should
Tried, it worked, superb.

Thanks guys.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)