Hey Orange Brat!

I am just studying this code and I found it's great!
I am adapting the camera style to that one in games like 'thief3', which is a combination of MovementType 0 and 3. (The camera orbits with the mouse, but the player model keeps its orientation, like a freelook. But when the player hits a key or a mouse button, the player model makes a turn to get aligned to the camera target direction, as to run/walk/strafe/attack in the direction the camera is looking).

I only found a strange thing at the end of moveCam():

Code:
  
c_trace(cam_centre.x,cam_pos.x, ignore_me + ignore_passable + ignore_models + ignore_sprites);
if(trace_hit == 0) // trace hit something
{
vec_diff(temp.x,cam_pos.x,target.x);
vec_diff(cam_pos.x,cam_pos.x,temp.x);
}

vec_set(camera.x,cam_pos.x);
...





trace_hit should be -1 or 1 when c_trace hits something! Why is it tested against Zero? However, I tried (trace_hit !=0) and it never was TRUE. I made a test, and found out that trace_hit is always zero.

My guess is that someone quick-fixed a non working IF by changing it to (trace_hit == 0) as a test, and since it worked, it was left as it is. But what is inside the brackets is executed all the time anyway! The IF could be completely removed.

So why this is working anyway? I traced the code, and it works because, when c_trace fails the hit, target.x gets the same value of cam_pos. So...

vec_diff(temp.x,cam_pos.x,target.x); //temp.x gets a value of {0,0,0}
vec_diff(cam_pos.x,cam_pos.x,temp.x); //cam_pos is not changed.

When the c_trace HITS something, the same two instructions do change cam_pos value.

What puzzles me is that the trace_hit var is just not working after c_trace. Would this be a bug?

Regards,
Emilio




EDIT EDIT EDIT
I just added the cam code to a new, clean project, and it works as expected. It seems there's something in the test level you sent that prevents trace_hit to work.

For my project to work, I just had to change the line:

if(trace_hit != 0) // trace hit something

Last edited by eleroux; 08/13/06 02:26.