Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, TedMar, dr_panther), 1,049 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Another, but different camera issue... #376858
07/07/11 05:44
07/07/11 05:44
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
emo10001 Offline OP
Newbie
emo10001  Offline OP
Newbie

Joined: Jun 2008
Posts: 37
Oklahoma City, OK
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


"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
Re: Another, but different camera issue... [Re: emo10001] #376862
07/07/11 06:05
07/07/11 06:05
Joined: Aug 2008
Posts: 482
B
bart_the_13th Offline
Senior Member
bart_the_13th  Offline
Senior Member
B

Joined: Aug 2008
Posts: 482
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);
	}
}
...



Re: Another, but different camera issue... [Re: emo10001] #376863
07/07/11 06:15
07/07/11 06:15

M
Malice
Unregistered
Malice
Unregistered
M



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);
	}
}



Last edited by Malice; 07/07/11 06:16.
Re: Another, but different camera issue... [Re: ] #376963
07/08/11 03:43
07/08/11 03:43
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
emo10001 Offline OP
Newbie
emo10001  Offline OP
Newbie

Joined: Jun 2008
Posts: 37
Oklahoma City, OK
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


"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1