2 registered members (Ayumi, 1 invisible),
584
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
problem with entity movement
#250264
02/06/09 22:55
02/06/09 22:55
|
Joined: Nov 2007
Posts: 13 Germany / Munich
V_Sola
OP
Newbie
|
OP
Newbie
Joined: Nov 2007
Posts: 13
Germany / Munich
|
Hi guys,
I want my model to move on an certain key. But up until now after i pressed for example Z the model continues moving. So how could I tell the engine: when I am holding W - Move the model with a regular speed until I stop holding ? that's my Code:
till now
//////////////////////////////////////////////////////////////////// #include <acknex.h> #include <default.c>
////////////////////////////////////////////////////////////////////
ENTITY* wizard;
////////////////////////////////////////////////////////////////////
function move_up() { wizard.z += 5; // addiere jedes mal, wenn diese Funktion aufgerufen wird 5 Quants auf die Höhe von wizard } function move_down() { wizard.z -= 5; } function move_ahead() { while(1) { wizard.x += 5*time_step*; wait(1); } }
function move_back() { while(1) { wizard.x += -5* time_step; wait(1); } } function main() { //video_mode = 7; // 800x600 pixels video_switch (8,32,1); level_load ("Drohne_Levelc.wmb"); on_u = move_up; on_i = move_down; on_z = move_ahead; on_y = move_back;
} action wizard_with_pointer() { wizard = my; my.ambient = 100; } action wizard_simple() { my.ambient = 100; }
P.S does it gave any value for a model's speed?
Last edited by V_Sola; 02/06/09 22:57.
|
|
|
Re: problem with entity movement
[Re: V_Sola]
#250291
02/07/09 06:57
02/07/09 06:57
|
Joined: Oct 2008
Posts: 218 Nashua NH
heinekenbottle
Member
|
Member
Joined: Oct 2008
Posts: 218
Nashua NH
|
A much more concise method would be using the key_XX variables (where XX is the key being pressed). These variables are 0 if not pressed, 1 if pressed and can be used in any equation. They are also predefined. So we can take move_up, move_down, move_ahead and move_back and condense them into shorter lines of code:
action wizard_with_pointer()
{
my.ambient = 100;
while(1)
{
my.x = 5 * (key_z - key_y) * time_step;
my.z = 5 * (key_i - key_u) * time_step;
wait(1);
}
} The way it works is this: Key Z is pressed, Key Y is not pressed: my.x = 5 * (1 - 0) * time_step = 5 * 1 * time_step = 5 * time_step Key Y is pressed, Key Z is not pressed: my.x = 5 * (0 - 1) * time_step = 5 * -1 * time_step = -5 * time_step Both are pressed: my.x = 5 * (1 - 1) * time_step = 5 * 0 * time_step = 0 Neither are pressed my.x = 5 * (0 - 0) * time_step = 5 * 0 * time_step = 0 This removes the need for those 4 functions and the four on_key commands in function main.
|
|
|
Re: problem with entity movement
[Re: heinekenbottle]
#250324
02/07/09 12:10
02/07/09 12:10
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Hey heinekenbottle, I think you done a typing error, shouldnt it be as follows? Note the ' +=' instead of just '='. while(1)
{
my.x += 5 * (key_z - key_y) * time_step;
my.z += 5 * (key_i - key_u) * time_step;
wait(1);
} Anyway, another way to look at it is like so (and a bit more flexible IMHO). function move_up()
{
//Sorry I cant read this comment so I'll leave up & down unchanged
wizard.z += 5; // addiere jedes mal, wenn diese Funktion aufgerufen wird 5 Quants auf die Höhe von wizard
}
function move_down()
{
wizard.z -= 5;
}
function move_ahead()
{
wizard.x += 5*time_step*;
}
function move_back()
{
wizard.x += -5* time_step;
}
function main()
{
//video_mode = 7; // 800x600 pixels
video_switch (8,32,1);
level_load ("Drohne_Levelc.wmb");
//
while(1)
{
if(key_u == 1) move_up();
if(key_j == 1) move_down();
if(key_z == 1) move_ahead();
if(key_y == 1) move_back();
wait(1);
}
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: problem with entity movement
[Re: V_Sola]
#250370
02/07/09 15:41
02/07/09 15:41
|
Joined: Oct 2008
Posts: 218 Nashua NH
heinekenbottle
Member
|
Member
Joined: Oct 2008
Posts: 218
Nashua NH
|
c_move(my, nullvector, nullvector, GLIDE );
my.x += 5 * (key_a - key_d) * time_step;
my.y += 5 * (key_s - key_w) * time_step;
my.pan += -50 * mouse_force.x * time_step;
You have c_move in here, but you aren't using it. c_move has two vectors, the first one is relative distance, the second it absolute. Relative will make the model move in relation to his orientation and origin, so all we need to do is put all of this into c_move:
action wizard_with_pointer()
{
VECTOR speed;
//...rest of code
while(1)
{
my.pan = -50 * mouse_force.x * time_step;
speed.x = 5 * (key_a - key_d) * time_step;
speed.y = 5 * (key_s - key_w) * time_step;
c_move(my,speed,nullvector,IGNORE_PASSABLE | GLIDE);
//...rest of code
|
|
|
Re: problem with entity movement
[Re: heinekenbottle]
#250413
02/07/09 20:24
02/07/09 20:24
|
Joined: Nov 2007
Posts: 13 Germany / Munich
V_Sola
OP
Newbie
|
OP
Newbie
Joined: Nov 2007
Posts: 13
Germany / Munich
|
now my Code looks like this:
(...) action wizard_with_pointer() { wizard = my; my.ambient = 100; //VECTOR speed;
while(1) { my.pan += -50 * mouse_force.x * time_step; my.x += 5 * (key_a - key_d) * time_step; my.y += 5 * (key_s - key_w) * time_step; c_move (my,my,nullvector,IGNORE_PASSABLE | GLIDE); camera.x = my.x; camera.y = my.y + 150; camera.z = my.z + 15; camera.pan = my.pan + 270; camera.tilt = - 12; wait(1); } } (...) but unfortunately it doesn't work what's my mistake?
Last edited by V_Sola; 02/07/09 20:25.
|
|
|
Re: problem with entity movement
[Re: V_Sola]
#250440
02/07/09 23:12
02/07/09 23:12
|
Joined: Oct 2008
Posts: 218 Nashua NH
heinekenbottle
Member
|
Member
Joined: Oct 2008
Posts: 218
Nashua NH
|
c_move (my,[b]my[/b],nullvector,IGNORE_PASSABLE | GLIDE); You placed a pointer where there should be a vector. "my" is a pointer. In these two lines:
my.x += 5 * (key_a - key_d) * time_step;
my.y += 5 * (key_s - key_w) * time_step; Replace "my" with a vector and put that vector in the c_move command.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|