Camera Collision + Without Digging into walls

Posted By: Hellcrypt

Camera Collision + Without Digging into walls - 11/25/05 22:04

Hey, a lot of people kept asking for a camera collision, so here is one
Code:
  
var Temp_distance = 0;
var Distance_traced = 0;
Function Camera_Collision()//include this in your camera code
{
my = player;
trace_mode = ignore_me + ignore_passable + use_box + ignore_models;//you can remove ignore_models if your level is made with a lot of models.
vec_set(temp_distance.x, camera.x);
Distance_traced = trace(player.x, Temp_distance.x)
if((Distance_traced != 0))
{
Distance_traced -= .05;
camera.x = player.x - distance_traced * cos(camera.pan)-1;
camera.y = player.y - distance_traced * sin(camera.pan)-1;
}
}


It's similar to one of the AUM's except it won't dig into walls and some modifications.
Posted By: TeutonicDarkness

Re: Camera Collision + Without Digging into walls - 12/06/05 05:53


Is this meant to be a "stand script"
or to go with Template 5 or template 6?

Just curious before I try anything..





*** Teutonic Darkness ***
Posted By: sempronius

Re: Camera Collision + Without Digging into walls - 12/06/05 07:42

It should probably be added to or called from a stand-alone camera script.
Posted By: Hellcrypt

Re: Camera Collision + Without Digging into walls - 12/06/05 15:27

Yep just make a camera that will follow the player, then include Camera_Collision(); inside your camera code.
Posted By: Anonymous

Re: Camera Collision + Without Digging into walls - 12/06/05 16:34

Thanks, this is helpful, I had thought of making my own but never got around to it.
Posted By: RJDL

Re: Camera Collision + Without Digging into walls - 12/06/05 17:29

ah, it works perfect, just what i needed! thanx a lot!
Posted By: Anonymous

Re: Camera Collision + Without Digging into walls - 12/09/05 20:36

Does that work for FPS? Or just following cam?
Posted By: Hellcrypt

Re: Camera Collision + Without Digging into walls - 12/10/05 00:01

hmm, I only tested it for following camera. For Fps your character itself should create a sort of collision for the camera. If you have any problems with that let me know.
Posted By: alphaindigo

Re: Camera Collision + Without Digging into walls - 12/13/05 19:49

thanks !
realy needed a decent one of these...
Posted By: Hellcrypt

Re: Camera Collision + Without Digging into walls - 12/27/05 16:03

Hey folks, because of everyone using models for levels now. Here is an updated code that will work with model collision as well, thanks to Dima.
Code:
  
Function Camera_move()
{
while(1)
{
c_rotate(my, vector(-1 * (11 * mouse_force.x * time - 1.5 * ((key_a - key_d) + (key_cul-key_cur))),0,0), glide+Use_box);
camera.x = player.x - camera_distance * cos(player.pan);
camera.y = player.y - camera_distance * sin(player.pan);
camera.z = player.z + camera_height;
camera.pan = player.pan;
camera.tilt += 8 * mouse_force.y * time;
camera_distance = min(max(camera_distance,5),500);
Camera_collision();
wait(1);
}
}

Function Camera_Collision()
{
my = player;
Distance_traced = c_trace(player.x, camera.x,ignore_me + ignore_passable+use_box);
if((Distance_traced != 0))
{
Distance_traced -= 5;
camera.x = player.x - distance_traced * cos(camera.pan);
camera.y = player.y - distance_traced * sin(camera.pan);
}
}


Posted By: JoraSell

Re: Camera Collision + Without Digging into walls - 12/29/05 13:50

Hey, it seems to me to be a much better idea to program something like this on your own and gain experience... Oh well, just a thought.
Posted By: Hellcrypt

Re: Camera Collision + Without Digging into walls - 12/29/05 14:05

I agree trial and error is good for learning, but for some of those people who don't have time or are not scripters this would be good. This way you could also learn how you trace from the player to the camera.
Posted By: Hellcrypt

Re: Camera Collision + Without Digging into walls - 02/19/06 16:52

Bump if anyone still needs a camera code with entity collision.
Posted By: kasimir

Re: Camera Collision + Without Digging into walls - 02/21/06 15:21

THANK YOU VERY MUCH FOR THIS CODE - ITS PERFECT
i modified it this way, i think you will like it:

define _camera_dist_min, 64;
define _camera_dist_max, 512;

var camera_dist = _camera_dist_max;

function Camera_Collision()
{
var camera_dist_traced;
trace_mode = ignore_me + ignore_models + ignore_passable + use_box;
camera_dist_traced = trace(player.x, camera.x);
if(camera_dist_traced != 0)
{
camera.x = player.x - camera_dist_traced * cos(camera.pan) * cos(camera.tilt);
camera.y = player.y - camera_dist_traced * sin(camera.pan) * cos(camera.tilt);
camera.z = player.z - camera_dist_traced * sin(camera.tilt);
}
}

function camera_move
{
while(1)
{
if(mouse_left)
{
camera.pan -= 50 * mouse_force.x * time;
camera.tilt = min(max(ang(camera.tilt + 50 * mouse_force.y * time),-90),15);
}

camera_dist = min(max(camera_dist + mickey.z * time,_camera_dist_min),_camera_dist_max);

camera.x = player.x - camera_dist * cos(camera.pan) * cos(camera.tilt);
camera.y = player.y - camera_dist * sin(camera.pan) * cos(camera.tilt);
camera.z = player.z - camera_dist * sin(camera.tilt);

Camera_collision();

wait(1);
}
}

while pressing mouse_left you can change the camera pan AND TILT
with mouse wheel you can change the camera dist!

i think is a littlebit more usable...
© 2023 lite-C Forums