0 registered members (),
1,089
guests, and 10
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Creating camera view toggle 1st person to 3rd person
#376427
07/02/11 20:54
07/02/11 20:54
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
Hey everyone, I've been experimenting with what I was hoping would be a simple camera toggle between 3rd person and 1st person point of view. The functionality seems to work. It switches between the 2 views, but after I switch the first time...my pan starts to look shaky and stutters. Any thoughts? Here's the function:
function camera_follow(ENTITY* ent)
{
var camx = -150;
var camy = 10;
var camz = 50;
var camtilt = -13;
// var camx;
// var camy;
// var camz;
// var camtilt;
while(1)
{
if(key_9)
{
camx = -150;
camy = 10;
camz = 50;
camtilt = -13;
}
if(key_0)
{
camx = 5;
camy = 0;
camz = 5;
camtilt = 0;
}
vec_set(camera.x,vector(camx,camy,camz)); // camera position relative to the player
vec_rotate(camera.x,ent.pan); // rotate the camera position with the player
vec_add(camera.x,ent.x); // add player position
vec_set(camera.pan,vector(ent.pan,camtilt,0)); // look in player direction, slighty down
wait(1);
}
}
"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
|
|
|
Re: Creating camera view toggle 1st person to 3rd person
[Re: MrGuest]
#376464
07/03/11 04:45
07/03/11 04:45
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
I think I know what you mean, but even if I do it like this it makes no difference:
function camera_follow(ENTITY* ent)
{
var camx;
var camy;
var camz;
var camtilt;
proc_mode = PROC_EARLY;
while(1)
{
if(key_9)
{
camx = -150;
camy = 10;
camz = 50;
camtilt = -13;
}
if(key_0)
{
camx = 5;
camy = 0;
camz = 5;
camtilt = 0;
}
vec_set(camera.x,vector(camx,camy,camz)); // camera position relative to the player
vec_rotate(camera.x,ent.pan); // rotate the camera position with the player
vec_add(camera.x,ent.x); // add player position
vec_set(camera.pan,vector(ent.pan,camtilt,0)); // look in player direction, slighty down
wait(1);
}
}
Is that what you're talking about?
"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
|
|
|
Re: Creating camera view toggle 1st person to 3rd person
[Re: emo10001]
#376536
07/04/11 05:32
07/04/11 05:32
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
Well I've made a discovery...the shaky part only happens after I've switched from 3rd person to 1st, and then back to 3rd. Then..at that point...if I switch back to 1st person and then back to 3rd person REALLY fast 1 time....it goes away.
But I'd rather not have to tell my players to do that LOL!
I'm hoping I can get this working...seems like a nice way to do camera perspective switching in just one camera function.
Anybody got anymore ideas?
"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
|
|
|
Re: Creating camera view toggle 1st person to 3rd person
[Re: Superku]
#376572
07/04/11 14:49
07/04/11 14:49
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
I call it in my player_move() code as:
camera_follow(me);
It's the first line in the player_move() section.
"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
|
|
|
Re: Creating camera view toggle 1st person to 3rd person
[Re: Superku]
#376855
07/07/11 03:57
07/07/11 03:57
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
Thanks for the advice Superku, but that didn't make any difference either. I think the function and the "if then" statement just didn't sit to well together (at least for camera functions). I broke out each camera as it's own function and then call them from another function...and the shaky/jittery camera has stopped. Here's what I wound up doing:
function camera_1stperson()
{
while(1)
{
camera.x = my.x + 11 * cos(my.pan);
camera.y = my.y + 11 * sin(my.pan);
camera.z = my.z + 25;
camera.pan = my.pan;
camera.tilt = 0;
camera.roll = 0;
wait(1);
}
}
function camera_3rdperson()
{
while(1)
{
camera.x = my.x - 150 * cos(my.pan);
camera.y = my.y - 150 * sin(my.pan);
camera.z = my.z + 50;
camera.pan = my.pan;
camera.tilt = -13;
camera.roll = 0;
wait(1);
}
}
function camera_3rdperson2()
{
while(1)
{
camera.x = my.x - 250 * cos(my.pan);
camera.y = my.y - 250 * sin(my.pan);
camera.z = my.z + 200;
camera.pan = my.pan;
camera.tilt = -25;
camera.roll = 0;
wait(1);
}
}
function select_cameras()
{
while(1)
{
if(key_7)
{camera_1stperson();}
if(key_8)
{camera_3rdperson();}
if(key_9)
{camera_3rdperson2();}
wait(1);
}
}
Last edited by emo10001; 07/07/11 04:00.
"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
|
|
|
Re: Creating camera view toggle 1st person to 3rd person
[Re: emo10001]
#376883
07/07/11 11:09
07/07/11 11:09
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
That's not a good solution, every time you press a key, a new while loop starts and the old camera_Xstperson-loops never stop. If-statements are fine with camera functions, why should they make any problems?
My advice: Return to your old code, use debug-features (don't forget DEBUG_VAR, diag_var, ...), reduce the code to a minimum until you isolate the problem.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
|