# Directions and Vectors problem

This topic is 5024 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to make FPS-style navigation, and i'm using the following code:
UpdatePlayer()
{
vec3 x_axis(1,0,0);
vec3 y_axis(0,1,0);
vec3 z_axis(0,0,1);
vec3 angles;
clamp(Player.Dir.x,-1,1);
clamp(Player.Dir.y,-1,1);
clamp(Player.Dir.z,-1,1);
if(Player.State[MOVELEFT])
{
angles.x += Player.DPS * GameInterval;
while(angles.x < 0)
{
angles.x += 360;
}
while(angles.x > 360)
{
angles.x -= 360;
}
}
if(Player.State[MOVERIGHT])
{
angles.x -= Player.DPS * GameInterval;
while(angles.x < 0)
{
angles.x += 360;
}
while(angles.x > 360)
{
angles.x -= 360;
}
}
Player.Dir.Normalize();
Player.Pos = Player.Pos + ((Player.Dir * Player.Speed) * GameInterval);
}


every frame after updating the player, i place the camera at Player.Pos and make it look at Player.Pos + Player.Dir the problem is that if i keep turning left or right, i cannot make a 90 degree turn. i reach a maximum of 80 degrees and it stops. besides, from around 65 degrees and above, the turning speed gets slower as the angle gets bigger... can someone plz tell me what's the problem?

##### Share on other sites
Maybe insted of clamping your Player.Dir vector, you should try to normalize it. It does the same thing, and keeps the vector direction true. Thats the only thing I can see might be wrong.

##### Share on other sites
My apology, but from the code above it seems that you are missing the concept of so-called "navigation".

You cannot get (x,y,z) directly from (angx,angy,angz), one by one. They affect each other.
If you are willing to perform full-3D, entire-arbitrary look direction, then you will have to go with quaternions. Try digging within this site's articles.

But if you are pointing into something like quake's navig, then it's a whole another story.

What you've got to keep is then:
angleXZ [0, 2*pi] - your angle with X axis, on XZ plane, that is, when looking from above.
angleY [-pi, pi] - your angle with XZ plane.

You can of course go with 180 insted of pi.

Your looking dir would then be calculated like:
dir.x = cos(angleXZ) * cos(angleY);
dir.z = sin(angleXZ) * cos(angleY);
dir.y = sin(angleY);

Also, if you are using gl, your dir.z should be negated.

/def

1. 1
Rutin
31
2. 2
3. 3
4. 4
5. 5

• 13
• 41
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632964
• Total Posts
3009536
• ### Who's Online (See full list)

There are no registered users currently online

×