c_trace for camera collision problem (SOLVED)

Posted By: Theil

c_trace for camera collision problem (SOLVED) - 10/12/11 20:02

I've got this piece of code for the camera on a third person view

Code:
if(c_trace(my.x,camera.x,IGNORE_ME | IGNORE_PASSENTS | IGNORE_MAPS | IGNORE_PASSABLE | IGNORE_SPRITES | IGNORE_CONTENT) > 0)
{
	vec_set(camera.x,target);
	vec_add(camera.x,normal);
}
else
{
	camera.x = me.x - camera_distance * cos(me.pan); 
	camera.y = me.y - camera_distance * sin(me.pan); 
	camera.z = me.z + camera_distance;
	camera.tilt = -(camera_distance/3);
	camera.pan = me.pan;
}



But when I test it and I put the player in front of a wall I get a flickering effect, it's like the camera is going forward and backward like if it is executing the if statement and right after that it runs the else statement, what do you think is the problem here?

Here is a gif that illustrates my problem:


Posted By: MrGuest

Re: c_trace for camera collision problem - 10/12/11 23:30

i'd put an epilepsy warning on this thread tongue

try setting the camera.pan before you calculate position
Posted By: Theil

Re: c_trace for camera collision problem - 10/13/11 00:22

Hahaha I thought the same about the epilepsy warning, let me try that, I guess I will later remove this picture.

Edit:

just tried this out

Code:
if(c_trace(my.x,camera.x,IGNORE_ME | IGNORE_PASSENTS | IGNORE_MAPS | IGNORE_PASSABLE | IGNORE_SPRITES | IGNORE_CONTENT) > 0)
{
	camera.pan = me.pan;
	vec_set(camera.x,target);
	vec_add(camera.x,normal);
}
else
{
	camera.pan = me.pan;
	camera.tilt = -(camera_distance/3);
	camera.x = me.x - camera_distance * cos(me.pan); 
	camera.y = me.y - camera_distance * sin(me.pan); 
	camera.z = me.z + camera_distance;
}



and it was just the same.
Posted By: Theil

Re: c_trace for camera collision problem - 10/13/11 00:30

I had to reduce the speed of the animation.
Posted By: Theil

Re: c_trace for camera collision problem - 10/13/11 19:11

Anyone? this problem looks so simple but I can't find a way to solve it. =/
Posted By: JibbSmart

Re: c_trace for camera collision problem - 10/14/11 02:20

You're tracing to the camera's position. When the camera is in front of the wall, the trace hits nothing, so you're putting it back at the old position. I recommend keeping track of where the camera would be if there were no obstacles, and trace to that position always.

I hope this helps laugh
Posted By: Theil

Re: c_trace for camera collision problem - 10/14/11 13:31

Wow thank you JibbSmart, that solved my problem, I defined a vector with the position of where the camera should be and traced the ray from there to the player and it worked perfectly, Thank you very much.
© 2024 lite-C Forums