Why is GetPlayerCameraFrontVector not working for me?
#1

I tried this

new Float,Float:y,Float:z;
GetPlayerCameraFrontVector(playerid,x,y,z);
CreateObject(345,x,y,z);

but for some reason it always creates the object at 0,0,0
Reply
#2

come on guys, easy question
Reply
#3

04:35 AM
05:15 AM

bump time very off.
Reply
#4

He just wants it to be at the top I guess.
Reply
#5

A vector is not a position which is what CreateObject expects. You have to use a combination of GetPlayerCameraPos and GetPlayerCameraFrontVector.

For example you could do something like this to create an object in the direction of where a player is looking.

pawn Код:
new
    Float:fPX, Float:fPY, Float:fPZ,
    Float:fVX, Float:fVY, Float:fVZ,
    Float:object_x, Float:object_y, Float:object_z;

// Change this constant to the the scale you want. A larger scale increases the distance from
// the camera. A negative scale will inverse the vectors and make them face in the opposite
// direction (i.e. behind the camera)
const
    Float:fScale = 6.0;

GetPlayerCameraPos(playerid, fPX, fPY, fPZ);
GetPlayerCameraFrontVector(playerid, fVX, fVY, fVZ);

object_x = fPX + floatmul(fVX, fScale);
object_y = fPY + floatmul(fVY, fScale);
object_z = fPZ + floatmul(fVZ, fScale);

CreateObject(345, object_x, object_y, object_z, 0.0, 0.0, 0.0);
You'll have to read about vector algebra if you wish to do more.
Reply
#6

I'm not very good with algebra to say the least but would i be right in thinking you could use this also to put an object behind a player by doing this?
pawn Код:
object_x = fPX - floatmul(fVX, fScale);
object_y = fPY - floatmul(fVY, fScale);
object_z = fPZ - floatmul(fVZ, fScale);
Sorry for silly question im shit at math need to do a course or something
This code would be usefull for me also. Thanks

Edit,
Quote:
Originally Posted by simon
// A negative scale will inverse the vectors and make them face in the opposite direction.
lol sorry didn't see that.
Reply
#7

Your first assumption is correct. It would be best to change only the fScale constant though as it's less code to change and makes you less prone to typing errors e.g. you might accidentally leave one as + rather than -
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)