2 registered members (AndrewAMD, Ayumi),
1,384
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
My movement script isn't working correctly, please help me. :)
#254106
03/01/09 09:38
03/01/09 09:38
|
Joined: Sep 2008
Posts: 76
Max_Prower
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2008
Posts: 76
|
Hey all, I'm having a little bit of trouble with this movement script. Basically what I've done is added a variable for movement speed (as variables automatically have an XYZ value) and given them a default value of zero. After that I added an ent_move function with relative movement as my move variable. Then I made a while loop that changes move_var's y value to 20 while the W key is pressed which moves it forward. But when I try to copy the while loop and assign it to a different key (so that I can make it move in all directions) it either only moves forward when I press W (as if ignoring the new while loop), or stops the movement working all-together. I simply can not figure out what I should do. I would be deeply appreciative if you could help me sort this out. Here is my script so far (the one that works): var move_var;
action PlayerAct
{
move_var.x = 0;
move_var.y = 0;
move_var.z = 0;
move_mode = GLIDE;
while(1)
{
ent_move (move_var, nullvector);
wait(1);
while(!key_w)
{
move_var.y = 20;
wait(1);
}
}
} And here is where it doesn't work:
var move_var;
action PlayerAct
{
move_var.x = 0;
move_var.y = 0;
move_var.z = 0;
move_mode = GLIDE;
while(1)
{
ent_move (move_var, nullvector);
wait(1);
while(!key_w)
{
move_var.y = 20;
wait(1);
}
while(!key_s)
{
move_var.y = -20; //This one doesn't work, and stops the other one from working as well.
wait(1);
}
}
}
|
|
|
Re: My movement script isn't working correctly, please help me. :)
[Re: Max_Prower]
#254116
03/01/09 10:23
03/01/09 10:23
|
Joined: Nov 2008
Posts: 354 saeculum II
MPQ
Senior Member
|
Senior Member
Joined: Nov 2008
Posts: 354
saeculum II
|
the second script cannot work: if key w is not pressed (!key_w), your player will move 20Q coincident if key s is not pressed (!key_s), your player will move -20Q This combination cannot work. Which kind of movement do you want? The movement does not seem to be functionally!
while (1)
{
if (key_w)
move_var.y += 20;
if (key_s)
move_var.y -= 20;
}
Last edited by MPQ; 03/01/09 10:33.
new project in early stage...
Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
|
|
|
Re: My movement script isn't working correctly, please help me.
[Re: MPQ]
#254120
03/01/09 10:45
03/01/09 10:45
|
Joined: Sep 2008
Posts: 76
Max_Prower
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2008
Posts: 76
|
Any movement that moves whilst I hold a key down and not at any other time is the kind I'm looking for. while (key_w == on)
{
move_var.y = 20;
wait(1);
} For some reason, this makes it so that when I press W and let go, it moves until I hold it down again.
Last edited by Max_Prower; 03/01/09 10:54.
|
|
|
Re: My movement script isn't working correctly, please help me.
[Re: Max_Prower]
#254123
03/01/09 11:00
03/01/09 11:00
|
Joined: Nov 2008
Posts: 354 saeculum II
MPQ
Senior Member
|
Senior Member
Joined: Nov 2008
Posts: 354
saeculum II
|
use my code i ve written in the last post without the "+" and "-".
Last edited by MPQ; 03/01/09 11:01.
new project in early stage...
Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
|
|
|
Re: My movement script isn't working correctly, please help me.
[Re: MPQ]
#254124
03/01/09 11:08
03/01/09 11:08
|
Joined: Sep 2008
Posts: 76
Max_Prower
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2008
Posts: 76
|
It doesn't work. Perhaps I should just scrap the whole variable idea and use c_move because that seems to work? Or is there some advantage in using variables?
Last edited by Max_Prower; 03/01/09 11:20.
|
|
|
Re: My movement script isn't working correctly, please help me.
[Re: Max_Prower]
#254125
03/01/09 11:21
03/01/09 11:21
|
Joined: Nov 2008
Posts: 354 saeculum II
MPQ
Senior Member
|
Senior Member
Joined: Nov 2008
Posts: 354
saeculum II
|
try this (maybe there are mistakes^^) i did not test it
VECTOR move_vector;
action PlayerAct
{
VECTOR* move_vector = nullvector;
while(1)
{
if (key_w)
move_var.y = 20;//move 20, if key w is pressed
if (key_s)
move_var.y = -20;//move -20, if key s is pressed
if ((!key_w && !key_s) || (key_w && key_s)) //if both keys are pressed or not pressed!!
move_car.y = 0; // if no key is pressed, set 0
c_move (my, move_vector, nullvector, GLIDE);
wait(1);
}
}
new project in early stage...
Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
|
|
|
Re: My movement script isn't working correctly, please help me.
[Re: Max_Prower]
#254128
03/01/09 11:31
03/01/09 11:31
|
Joined: Nov 2008
Posts: 354 saeculum II
MPQ
Senior Member
|
Senior Member
Joined: Nov 2008
Posts: 354
saeculum II
|
ok ;), what kind of game do you program?
new project in early stage...
Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
|
|
|
Re: My movement script isn't working correctly, please help me.
[Re: MPQ]
#254129
03/01/09 11:33
03/01/09 11:33
|
Joined: Sep 2008
Posts: 76
Max_Prower
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2008
Posts: 76
|
I'm trying to program my first game without templates, a third person shooter. The gameplay and graphics will be similar to American Mcgee's Alice. But the plot will be differnt and all that. It will follow the same principle though: The world's gone up-side down, the hero has to set it right.
At the moment, I'm trying to make a script that jumps when I press space; but I don't know how to do that. >.<
Last edited by Max_Prower; 03/01/09 11:42.
|
|
|
Re: My movement script isn't working correctly, please help me.
[Re: Max_Prower]
#254133
03/01/09 11:48
03/01/09 11:48
|
Joined: Nov 2008
Posts: 354 saeculum II
MPQ
Senior Member
|
Senior Member
Joined: Nov 2008
Posts: 354
saeculum II
|
this is not so difficult as it looks^^, think about it...
new project in early stage...
Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|