Getting axis in front of player.
#1

One thing has always puzzled me about sa-mp scripting. When I think of samp coordinates, I think of one huge 3D coordinated plane. Now the thing that truly puzzles me is how I will be able to spawn something like a vehicle or create an explosion in front of a player, because let's say I use GetPlayerPos passed by 3 floats. Now, how would I be able to get which axis the player is facing on so that the desired object will always spawn in front of the player no matter what angle he is facing.

In other words. This code below makes a car 3 gta units away from their position on the y-axis.
pawn Код:
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
CreateVehicle(/*params here*/,x,y + 3,z);
But what if a player is facing towards the negative side on the y-axis? The vehicle wouldn't spawn in front of him anymore. So how will I be able to make sure a vehicle or an explosion will always occur 3 units in front of the player regardless of which way he's facing? Is this possible? It's just something that has always puzzled me. Maybe it's something so simple that I missed somewhere, I'm not so sure. But I would appreciate if anyone could be of any help. Thank you.
Reply
#2

Here you go.

Код:
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
CreateVehicle(*params here*,x + 2*floatcos(90+a, degrees), y+ 2*floatsin(90-a, degrees), z);
And if the angle isn't good modify this number "x + 2*floatcos(90+a, degrees), y+ 2*floatsin(90-a, degrees), z", change it with different numbers like 120...etc.
Reply
#3

Thank you for pointing me in the right direction. I'm now reading the float library wiki. Once again thank you!

EDIT:

Can someone out there explain to me exactly what a sine or a cosine of a float is? I found an article about it, having to do with trigonometry which is far out of my area of expertise. Anyone?
Reply
#4

You're welcome.
Reply
#5

Quote:
Originally Posted by Bogdan1992
Посмотреть сообщение
Here you go.

Код:
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
CreateVehicle(*params here*,x + 2*floatcos(90+a, degrees), y+ 2*floatsin(90-a, degrees), z);
And if the angle isn't good modify this number "x + 2*floatcos(90+a, degrees), y+ 2*floatsin(90-a, degrees), z", change it with different numbers like 120...etc.
why tf u multiply by 2 and 90+a shit? i suck at math..
teach us your ways master...
Reply
#6

taken from wikipedia:


The sine and cosine functions are related in multiple ways. The derivative of sin(x) is cos(x). Also they are out of phase by 90°: sin(pi/2 - x) = cos(x). And for a given angle, cos and sin give the respective x, y coordinates on a unit circle.



when you combine sin/cos, and use the same radius on both, ocassionally adding an offset on x,y axis, you can draw a circle.

argh, if i would have scrolled down, then i wouldnt have to link this: (lol i do it nevertheless heh)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)