Raised This Month: $32 Target: $400
 8% 

[TUT] Vectors from player view


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 04-28-2015 , 16:52   [TUT] Vectors from player view
Reply With Quote #1

I recommend reading this first: https://forums.alliedmods.net/showthread.php?t=91474

Once you've read that, you should understand 3D coordinates, vectors and angles handled by Half-Life. The XY-plane is where player moves along the flat ground, the Z-axis corresponds with up and down.

The angles of interest here correspond to:

1. Pitch: Angle from the XY-plane
Up being negative, down being positive

2. Yaw: Angle away from X-axis
Yaw = 0 along positive X-axis (obvious)
Yaw = 180 along negavite X-axis
Yaw = 90 along positive Y-axis
Yaw = -90 along nevative Y-axis


PHP Code:
new Float:fAngles
entity_get_vector
(idEV_VEC_anglesfAngles); 
Gives you the angles in the direction of which player is looking.
So for example, if player is looking down by 45 degrees, and 60 degrees away from the X-axis towards the positive Y-axis, this would return

PHP Code:
fAngles[0] = 45.0
fAngles
[1] = 60.0 
If all you want is a direction straight UP, RIGHT or FORWARD all you need to do is:

PHP Code:
new FloatfVector
angle_vector
(fAngles, ***, fVector);

// ***
// ANGLEVECTOR_UP for direction pointing UP
// ANGLEVECTOR_RIGHT for direction point RIGHT
// ANGLEVECTOR_FORWARD for direction point FORWARD 
If you want DOWN, LEFT or BACKWARDS you will use the same code from above and then multiply your vector by -1

PHP Code:
new FloatfVector
angle_vector
(fAngles, ***, fVector);

fVector[0] *= -1
fVector
[1] *= -1
fVector
[2] *= -1

// ***
// ANGLEVECTOR_UP for direction pointing DOWN
// ANGLEVECTOR_RIGHT for direction point LEFT
// ANGLEVECTOR_FORWARD for direction point BACKWARD 
If you want a direction other than these, you will need to use your imagination.
Imagine a vector pointing in the player's view direction. You can manipulate the values you get from EV_VEC_angles to get any other direction you may want.

For example, if you want a vector that points in the sample direction as player's view along the XY-plane but in a different direction up and down, all you have to do is set fAngles[0] to the direction you want

PHP Code:
fAngles[0] = 0.0 // Gives direction parallel to XY-plane
fAngles[0] = -45.0 // Gives direction pointing 45 degrees up
fAngles[0] += 10.0 // Gives direction 10 degrees down from player's view 
If you want to change the direction along the XY-plane, you have to edit the second value:

PHP Code:
fAngles[1] += 90.0 // Gives direction to the left of player
fAngles[1] -= 60.0 // Gives direction 60 degrees to the right of player's view 
Note that for the yaw angle, you have to add or subtract a value in order to have a reference. You can also do that for the pitch angle as shown, but it is not necessary. Once you have changed these angles to face in the direction you want, you can create your unit vector:

PHP Code:
new FloatfVector
angle_vector
(fAnglesANGLEVECTOR_FORWARDfVector); 
Note that we use ANGLEVECTOR_FORWARD here, and remember it is a unit vector, so you still need to multiply all three values ([0], [1] and [2]) by the magnitude you want.

So a final example:

PHP Code:
new Float:fAnglesFloat fVelocity;
entity_get_vector(idEV_VEC_anglesfAngles);

fAngles[0] = -50.0;
fAngles[1] += 70.0;

angle_vector(fAnglesANGLEVECTOR_FORWARDfVelocity);

fVelocity[0] *= SPEED;
fVelocity[1] *= SPEED;
fVelocity[2] *= SPEED;

entity_set_vector(idEV_VEC_velocityfVelocity); 
Would give player velocity 50 degrees UP and 70 degrees to the LEFT of player.

_

Last edited by vitorrossi; 04-28-2015 at 17:00.
vitorrossi is offline
GoldBoy1
Junior Member
Join Date: Apr 2015
Old 05-04-2015 , 09:48   Re: [TUT] Vectors from player view
Reply With Quote #2

Thanks a lot !
GoldBoy1 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:42.


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