Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,388 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
toggle key trouble #315780
03/18/10 23:42
03/18/10 23:42
Joined: Jan 2010
Posts: 145
Doc_Savage Offline OP
Member
Doc_Savage  Offline OP
Member

Joined: Jan 2010
Posts: 145
so i just figured out how to set up my game to toggle between first and 3rd person. problem is, i have to hold the key down to get it to stay in first. id love it if i could just tap the key to get it to switch. so far i have this as the part that switches it:


while (key_t == 1) {wait (1);}
{


now how can i change this part so it toggles instead of me having to hold the t key down? any help ids appreciated laugh



and later i plan on having it so you can move the 3rd person view around with the mouse, any help to get me started there would be appreciated also. if not its cool, i can try to learn on my own

Last edited by Doc_Savage; 03/18/10 23:54.

Do not concern yourself with my race, personality or origin. find my record in the pits, and then make your wager.
Re: toggle key trouble [Re: Doc_Savage] #315812
03/19/10 09:33
03/19/10 09:33
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
That code line you posted does not explain very much about the structure of your code and the idea of your approach.
Thus I'll just propose an approach to solve your problem:
1. Use a variable or skill value to determine which camera view mode is activ:
Code:
var camera_ViewMode = 0; // 0=1st Person, 1=3rd Person



2. Define a basic function to toggle between the values. Because in this example we use only two (0 and 1) its rather easy:
Code:
function camera_ToggleViewMode()
{
  camera_ViewMode = !camera_ViewMode;
}


The ! operator negates the value of the camera_ViewMode variable.
Thus !0 = 1, !1 = 0

3. Assign that toggle function to your key. To do so write in the main function:
Code:
on_t = camera_ToggleViewMode;



4. Use the camera_ViewMode variable in a camera function to calculate the desired position of the camera and its angle.
Note: Do NOT use while loops in the camera_Update function in this approach!
Code:
function camera_Update()
{
  if(camera_ViewMode == 0) // 1st Person
  {
    ...
  }
  else // 3rd Person
  {
    ...
  }
}



5. Call this function at the end of your player's while loop (just before the wait(1):
Code:
action player_act
{
  player = me;
  ...
  while(1)
  {
    // movement + gravity + everything else

    camera_Update();
    wait(1);
  }
}



Hope this helps.

About your other question:
You would have to change the camera pan/tilt value with the mouse_force.x/y and then calculate the camera position using thoses angles, the player position and the offset of the camera. (this is the basic idea)

Re: toggle key trouble [Re: Xarthor] #315889
03/19/10 19:29
03/19/10 19:29
Joined: Jan 2010
Posts: 145
Doc_Savage Offline OP
Member
Doc_Savage  Offline OP
Member

Joined: Jan 2010
Posts: 145
ok basically with the help of the manual/help file i made this:

Code:
while (key_t == 1) {wait (-1);} // isometric view
		{
			camera.x = player.x - 200 * cos(player.pan);
			camera.y = player.y - 200 * sin(player.pan);
			camera.z = player.z + 100; // above the player
	                my.pan -= cam_pan_speed * (mouse_force.x) * time;
			camera.tilt += cam_tilt_speed * (mouse_force.y) * time;
			camera.tilt = clamp(camera.tilt, -56, 70);
		}



now for request reasons i cant show you another part of the code. but it is code for the first person view. and it is above this part. that part and this part are in one whole function.

as you can see i took your advice on getting the mouse to move in 3rd person. now my trouble is, some of your code is a bit.. advanced for me lol. i just dont get one thing about it, does this mean i should completely overwrite the function i have, save the camera settings from it and put them in your "function camera update"?


so essentially it would look like this?
Code:
function camera_Update()
{
  if(camera_ViewMode == 0) // 1st Person
  {
   [CENSORED FIRST PERSON CAMERA CODE]
  }
  else // 3rd Person
  {
      camera.x = player.x - 200 * cos(player.pan);
      camera.y = player.y - 200 * sin(player.pan);
      camera.z = player.z + 100; // above the player
      my.pan -= cam_pan_speed * (mouse_force.x) * time;
      camera.tilt += cam_tilt_speed * (mouse_force.y) * time;
      camera.tilt = clamp(camera.tilt, -56, 70);
  }
}




amidoinitrite?

i hope you understand my ramblings lol.

Last edited by Doc_Savage; 03/19/10 19:35.

Do not concern yourself with my race, personality or origin. find my record in the pits, and then make your wager.
Re: toggle key trouble [Re: Doc_Savage] #315891
03/19/10 19:47
03/19/10 19:47
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Quote:

i just dont get one thing about it, does this mean i should completely overwrite the function i have, save the camera settings from it and put them in your "function camera update"?

Yes.
But what you need to know: My approach is just one. There are many ways to construct this.

If you however choose to use that approach, remember to call the camera_Update function once each frame in the player's while loop.
I assume you have a player action which controls movement etc. and thus have a while loop inside that action.
As I said, call the camera_Update function right before the wait(1) of that while loop.

Re: toggle key trouble [Re: Xarthor] #315894
03/19/10 20:06
03/19/10 20:06
Joined: Jan 2010
Posts: 145
Doc_Savage Offline OP
Member
Doc_Savage  Offline OP
Member

Joined: Jan 2010
Posts: 145
im glad i got it right!

i do have a player action, yes. and while there may be others. yours is one i understand! haha. but how exactly do i call something? the manual has been very cryptic about this subject.

my mind is more an expert on texture creation, and modeling. sorry for all the questions tongue

Last edited by Doc_Savage; 03/19/10 20:08.

Do not concern yourself with my race, personality or origin. find my record in the pits, and then make your wager.
Re: toggle key trouble [Re: Doc_Savage] #315901
03/19/10 22:01
03/19/10 22:01
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
calling a function works the following way:
you write: function-name + () + ;
In your case you can call the camera_Update function just like this:
Code:
camera_Update();



That will call the function camera_Update.
Write that line before the wait(1) like I explained.

Re: toggle key trouble [Re: Xarthor] #315920
03/20/10 03:39
03/20/10 03:39
Joined: Jan 2010
Posts: 145
Doc_Savage Offline OP
Member
Doc_Savage  Offline OP
Member

Joined: Jan 2010
Posts: 145



it keeps saying paramater unkown camera_toggleviewmode

help?


Last edited by Doc_Savage; 03/20/10 04:38.

Do not concern yourself with my race, personality or origin. find my record in the pits, and then make your wager.
Re: toggle key trouble [Re: Doc_Savage] #315928
03/20/10 09:36
03/20/10 09:36
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
The compiler always say in which line that error occured. So please post the line which the compiler doesn't "like".

What else you need to check:
Is the function defined _before_ you assign it to a key?

Re: toggle key trouble [Re: Xarthor] #316004
03/20/10 17:42
03/20/10 17:42
Joined: Jan 2010
Posts: 145
Doc_Savage Offline OP
Member
Doc_Savage  Offline OP
Member

Joined: Jan 2010
Posts: 145
im not sure what you mean by define_before_you but i did every step you told me to do. and the line it dosent like is the one in my main that i put:

Code:
on_t = camera_ToggleViewMode;




error line whatever: paramater unkown camera_toggleviewmode

that is the only thing wrong, i can manually change views by switching:
Code:
if(camera_ViewMode == 0) // 1st Person

to 1. and deleting the line you told me to put in main. and the views both work, now is just the problem of switching between the 2. it says unkown parameter, do i need to add a define or a variable? btw youve been a fantastic help laugh

Last edited by Doc_Savage; 03/20/10 17:52.

Do not concern yourself with my race, personality or origin. find my record in the pits, and then make your wager.
Re: toggle key trouble [Re: Doc_Savage] #316007
03/20/10 18:12
03/20/10 18:12
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Well did you write a function named "camera_ToggleViewMode" in your script before the main function (best place to put this is in the camera code section of course).

See point #2 of my first post, thats all the function "camera_ToggleViewMode" needs to do in your case.

Page 1 of 2 1 2

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

Gamestudio download | 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