Spawn something relative to the player. -
IcyBlight - 01.06.2010
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.
Re: Spawn something relative to the player. -
(SF)Noobanatior - 01.06.2010
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;
}
Re: Spawn something relative to the player. -
IcyBlight - 01.06.2010
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.
Re: Spawn something relative to the player. -
jameskmonger - 01.06.2010
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.
Re: Spawn something relative to the player. -
IcyBlight - 01.06.2010
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?
Re: Spawn something relative to the player. -
jonrb - 01.06.2010
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
Re: Spawn something relative to the player. -
IcyBlight - 01.06.2010
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?
Re: Spawn something relative to the player. -
jonrb - 01.06.2010
Try it, but it should
Re: Spawn something relative to the player. -
IcyBlight - 01.06.2010
Quote:
Originally Posted by jonrb
Try it, but it should
|
Tried, it worked, superb.
Thanks guys.