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(id, EV_VEC_angles, fAngles);
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 Float: fVector
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 Float: fVector
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 Float: fVector
angle_vector(fAngles, ANGLEVECTOR_FORWARD, fVector);
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:fAngles, Float fVelocity;
entity_get_vector(id, EV_VEC_angles, fAngles);
fAngles[0] = -50.0;
fAngles[1] += 70.0;
angle_vector(fAngles, ANGLEVECTOR_FORWARD, fVelocity);
fVelocity[0] *= SPEED;
fVelocity[1] *= SPEED;
fVelocity[2] *= SPEED;
entity_set_vector(id, EV_VEC_velocity, fVelocity);
Would give player velocity 50 degrees UP and 70 degrees to the LEFT of player.
_