Another, but different camera issue...

Posted By: emo10001

Another, but different camera issue... - 07/07/11 05:44

Ok...now I've got 3 different camera views for my player. 1st person, 3rd person behind, and an alternate 3rd person behind. In my two 3rd person cameras, I have the camera.tilt set to a static value, but in my 1st person camera, I want the player to be able to adjust the camera.tilt with the pgup-pgdn keys and reset to 0 with "home" key. It works as long as I call my 1st person view first, but as soon as I change to either 3rd person view, and then try to switch back, the camera.tilt stays at the value of the 3rd person view you were in. Switching between the two third person views works just fine...but try to go back to 1st person view...and not only does the 1st person camera.tilt continue to be the same tilt as the last 3rd person view you were in, but the pgup-pgdn keys no longer funtion.

I figure it has to be something simple. I've trying resetting the camera.tilt to 0 in the camera_select function "if" statements (if key_7){camera.tilt = 0;}, but it only goes to zero briefly and then returns to whatever the previous 3rd person tilt was....or stays at 0 if you hold down the key_7.

I'm just not sure why the camera.tilt sticks.....

Again...here's my functions.

Code:
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 += (key_pgup-key_pgdn)*5*time_step;
	   if(key_home)
	   {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);
	}
}



If I take out the "camera.tilt += (key_pgup-key_pgdn)*5*time_step;" code altogether and just hard-code "camera.tilt = 0;}, it works...but then I have no player tilt.

Again...any help/thoughts/ideas are really appreciated!

-Emo
Posted By: bart_the_13th

Re: Another, but different camera issue... - 07/07/11 06:05

create a global variabel to contain the camera state
Code:
var camera_state = 1;
...
function select_cameras()
{	
	while(1)
	{
		if(key_7) camera_state = 1;
		if(key_8) camera_state = 2;
		if(key_9) camera_state = 3;
                switch(camera_state) 
                {
                      case 1: camera_1stperson();break
                      case 2: camera_3rdperson();break
                      case 3: camera_3rdperson2();break
                }
		wait(1);
	}
}
...


Posted By: Anonymous

Re: Another, but different camera issue... - 07/07/11 06:15

EDIT: Dang you bet me to the answer!

I know this is a dumb question but are killing the while(1) ... loops when you change cameras. Why does each camera function have a loop. Try this I didn't test it.

Malice

Code:
function camera_1stperson()
{
	   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 += (key_pgup-key_pgdn)*5*time_step;
	   if(key_home)
	   {camera.tilt = 0;}
	   camera.roll = 0;
	
}

function camera_3rdperson()
{
	   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;
	       
}

function camera_3rdperson2()
{
	
	   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;
	
}



function select_cameras()
{	
  var iCam_Mode=0;
	while(1)
	{
		if(key_7)
		{iCam_mode=1;}
		if(key_8)
		{iCam_mode=2;}
		if(key_9)
		{iCam_mode=3;}
                if(iCam_Mode==1)
                {camera_1stperson();}
                if(iCam_Mode ==2)
                {camera_3rdperson();}
                if(iCam_Mode==3)
                {camera_3rdperson2();}
		wait(1);
	}
}


Posted By: emo10001

Re: Another, but different camera issue... - 07/08/11 03:43

You guys were both right! Adding the camera state allowed me to do what I needed!

Thanks guys!

My final code is in my other semi-related post here:

http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=376427#Post376427
© 2024 lite-C Forums