AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Vectors - calculating position in front of a player (https://forums.alliedmods.net/showthread.php?t=160159)

t3hNox 06-25-2011 15:24

Vectors - calculating position in front of a player
 
I know that this problem has been already discussed, but I just can't find any useful topic about it.
I'm looking for a piece of code that can calculate origin, let's say, 40.0 units in front of a player. Height should be also observed (start point is a player, end point is the point where the player is aiming). It's probably some traceline function + xs, but I can't find any reference to xs functions therefore I don't know how to use them.

Exolent[jNr] 06-26-2011 14:49

Re: Vectors - calculating position in front of a player
 
Something simple:
Code:
new iEyesOrigin[ 3 ]; get_user_origin( iPlayer, iEyesOrigin, 1 ); new Float:vecEyesOrigin[ 3 ]; IVecFVec( iEyesOrigin, vecEyesOrigin ); new Float:vecDirection[ 3 ]; velocity_by_aim( iPlayer, 40, vecDirection ); new Float:vecAimOrigin[ 3 ]; xs_vec_add( vecEyesOrigin, vecDirection, vecAimOrigin ); // vecAimOrigin has 40 units away from where player is aiming

t3hNox 06-27-2011 08:06

Re: Vectors - calculating position in front of a player
 
Thank you, Exolent.
I tried to make some calculations myself but they didn't work correctly. This, on the other hand, seems to be working properly.


All times are GMT -4. The time now is 23:31.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.