0 registered members (),
18,767
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
toggle key trouble
#315780
03/18/10 23:42
03/18/10 23:42
|
Joined: Jan 2010
Posts: 145
Doc_Savage
OP
Member
|
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  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
Expert
|
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:
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:
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:
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!
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):
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
OP
Member
|
OP
Member
Joined: Jan 2010
Posts: 145
|
ok basically with the help of the manual/help file i made this:
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?
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
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
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
OP
Member
|
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 
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
Expert
|
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: 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
OP
Member
|
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: Xarthor]
#316004
03/20/10 17:42
03/20/10 17:42
|
Joined: Jan 2010
Posts: 145
Doc_Savage
OP
Member
|
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:
on_t = camera_ToggleViewMode;
error line whatever: paramater unkown camera_toggleviewmode that is the only thing wrong, i can manually change views by switching:
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 
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.
|
|
|
|