Making the camera follow an object?

Posted By: Jack2010

Making the camera follow an object? - 05/16/10 22:58

Hey guys! Is it possible to make the camera follow an object when it moves using the arrow keys (including tilt, pan, roll angles assigned to keys)? If so, how would I do it?

Thanks!
Posted By: Superku

Re: Making the camera follow an object? - 05/16/10 23:04

action object_with_camera() {
VECTOR o_speed;
while(1) {
my.pan += (key_a-key_d)*10*time_step;
o_speed.x = (key_w-key_s)*20*time_step;
o_speed.y = 0;
o_speed.z = -c_trace(my.x,vector(my.x,my.y,my.z-500),IGNORE_ME | IGNORE_PASSABLE);
c_move(me,o_speed,nullvector,GLIDE);

camera.x = my.x-300*cos(my.pan);
camera.y = my.y-300*sin(my.pan);
camera.z = my.z+150;
camera.pan = my.pan;
camera.tilt = -20;
wait(1);
}
}

Should work, untested.

EDIT: When reading your post a second time I'm not sure if I understood you correctly!?

BTW: Welcome to the gamestudio forums!
Posted By: Jack2010

Re: Making the camera follow an object? - 05/17/10 07:11

Originally Posted By: Superku
action object_with_camera() {
VECTOR o_speed;
while(1) {
my.pan += (key_a-key_d)*10*time_step;
o_speed.x = (key_w-key_s)*20*time_step;
o_speed.y = 0;
o_speed.z = -c_trace(my.x,vector(my.x,my.y,my.z-500),IGNORE_ME | IGNORE_PASSABLE);
c_move(me,o_speed,nullvector,GLIDE);

camera.x = my.x-300*cos(my.pan);
camera.y = my.y-300*sin(my.pan);
camera.z = my.z+150;
camera.pan = my.pan;
camera.tilt = -20;
wait(1);
}
}

Should work, untested.

EDIT: When reading your post a second time I'm not sure if I understood you correctly!?

BTW: Welcome to the gamestudio forums!


Thanks! Basically, I need the camera to follow the object both when it moves and when it tilts/pans/rolls, kind of like in the wizard shooter in the tutorial (workshop24 I think) but not just the pan angle.

Seems a bit confusing, eh?

Thanks again!
Posted By: wdlmaster

Re: Making the camera follow an object? - 05/17/10 10:27

Code:
vec_set (camera.pan,my.pan);
vec_set (camera.x,vector(-500,0,0));
vec_rotate (camera.x,camera.pan);
vec_add (camera.x,my.x);



the 2nd line gives the "offset" relative to the entity.
Posted By: Badrizmo

Re: Making the camera follow an object? - 05/23/10 06:06

@Jack: There was a tutorial that covers all sorts of cameras (first person, 3rd person, resident evil style cameras) I think you should take a look at it. Here is a link

http://www.opserver.de/coni_users/web_users/pirvu/au/tutorials/zipped/camtut.pdf
© 2023 lite-C Forums