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
2 registered members (AndrewAMD, dr_panther), 791 guests, and 5 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
Page 1 of 2 1 2
problem with entity movement #250264
02/06/09 22:55
02/06/09 22:55
Joined: Nov 2007
Posts: 13
Germany / Munich
V
V_Sola Offline OP
Newbie
V_Sola  Offline OP
Newbie
V

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] #250288
02/07/09 06:28
02/07/09 06:28
Joined: Sep 2003
Posts: 407
inside to my
er_willy Offline
Senior Member
er_willy  Offline
Senior Member

Joined: Sep 2003
Posts: 407
inside to my
function move_ahead()
{
wizard.x += 5*time_step*;
}


...
while(1)
{
on_u = move_up;
on_i = move_down;
on_z = move_ahead;
on_y = move_back;
wait(1);
}

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 Offline
Member
heinekenbottle  Offline
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:
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.


I was once Anonymous_Alcoholic.

Code Breakpoint;
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 Offline
Expert
EvilSOB  Offline
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 '='.
Code:
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).
Code:
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: EvilSOB] #250350
02/07/09 14:17
02/07/09 14:17
Joined: Nov 2007
Posts: 13
Germany / Munich
V
V_Sola Offline OP
Newbie
V_Sola  Offline OP
Newbie
V

Joined: Nov 2007
Posts: 13
Germany / Munich
thx everyone, my model is moving right.

how could I let the camera be constantly behind my model (3rd Person View) ?

Re: problem with entity movement [Re: V_Sola] #250352
02/07/09 14:25
02/07/09 14:25
Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
Cowabanga Offline
Expert
Cowabanga  Offline
Expert

Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
Put this code:

Code:
camera.x = wizard.x - 15; // change it like you want.
camera.y = wizard.y; // don't touch it!
camera.z = wizard.z + 5; // change it like you want.


Re: problem with entity movement [Re: Cowabanga] #250356
02/07/09 14:37
02/07/09 14:37
Joined: Nov 2007
Posts: 13
Germany / Munich
V
V_Sola Offline OP
Newbie
V_Sola  Offline OP
Newbie
V

Joined: Nov 2007
Posts: 13
Germany / Munich
Nice thx,
Now my code looks like this:

////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>


////////////////////////////////////////////////////////////////////

ENTITY* wizard;

////////////////////////////////////////////////////////////////////


}
function main()
{
//video_mode = 7; // 800x600 pixels
video_switch (8,32,1);
level_load ("Drohne_Levelc.wmb");


}a

action wizard_with_pointer()
{
wizard = my;
my.ambient = 100;
while(1)
{

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;

camera.x = my.x;
camera.y = my.y + 100;
camera.z = my.z + 15;

camera.pan = my.pan + 270;
camera.tilt = - 12;

c_move(my, nullvector, nullvector, GLIDE );
wait(1);
}
}

action wizard_simple()
{
my.ambient = 100;
}

My Problem is that the model moves absolutly and not relative.
Does anyone have a solution which doesn't need to change my code completly?

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 Offline
Member
heinekenbottle  Offline
Member

Joined: Oct 2008
Posts: 218
Nashua NH
Code:
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:
Code:
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



I was once Anonymous_Alcoholic.

Code Breakpoint;
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
V_Sola Offline OP
Newbie
V_Sola  Offline OP
Newbie
V

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 Offline
Member
heinekenbottle  Offline
Member

Joined: Oct 2008
Posts: 218
Nashua NH

Code:
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:

Code:
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.


I was once Anonymous_Alcoholic.

Code Breakpoint;
Page 1 of 2 1 2

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