vectors relative to player location while accounting for where theyre facing

Author Topic: vectors relative to player location while accounting for where theyre facing  (Read 1017 times)

i like to think ive got a good grip with vectors by now since ive been doing all sorts of stuff with them for the past two days but ive come across something that just has me stumped. so stumped that i cant really explain it in text so have some pictures.


lets say we have a player, and this player has three vectors in a vaguely triangular shape in front of his face. seems easy enough yea? (note: they aren't really connected, it's just there to convey them better)



how do i, make these vectors always remain in front of the players face. at the same position relative to his face. no matter where he is or wherever he's facing? what kind of crazy math stuff do i need to do to accomplish this?

All you really need is the relative forward, up, and right vector, and the rest is easy.

Code: [Select]
%forward = %player.getEyeVector(); //May have issues when freelooking, if so use [tt]getForwardVector()[/tt] and the z component of [tt]getEyeVector()[/tt]
%right = vectorCross(%forward, "0 0 1"); //Cross product returns a vector which is perpendicular to both input vectors
%up = vectorCross(%forward, %right); //This might actually be down, if so just swap the inputs

Using these vectors, you can scale them and add them to get any point relative to the player. eg:

Code: [Select]
%point = vectorAdd(vectorAdd(vectorScale(%forward, 2), vectorScale(%up, 0.3)), vectorScale(%right, 1));

%point will be a vector that is 2 units forward, 0.3 up, and 1 to the right, in front of the player.

doesnt seem to work since %forward is always near 0,0,0 regardless of player position

EDIT: nvm i added %point to %player.geteyepoint n it worked thx senpai bb :)
« Last Edit: September 25, 2015, 06:15:15 PM by Niblic² »


doesnt seem to work since %forward is always near 0,0,0 regardless of player position

EDIT: nvm i added %point to %player.geteyepoint n it worked thx senpai bb :)

%forward, %up, and %right are all vectors, not positions. %point was badly named.