Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, Grant, Neb), 908 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Player walk the way they are facing #248477
01/27/09 03:32
01/27/09 03:32
Joined: Jan 2008
Posts: 1,580
Blade280891 Offline OP
Serious User
Blade280891  Offline OP
Serious User

Joined: Jan 2008
Posts: 1,580
How can i get my player to walk the way they are facing?


My Avatar Randomness V2

"Someone get me to the doctor, and someone call the nurse
And someone buy me roses, and someone burned the church"
Re: Player walk the way they are facing [Re: Blade280891] #248483
01/27/09 04:52
01/27/09 04:52
Joined: Oct 2008
Posts: 218
Nashua NH
heinekenbottle Offline
Member
heinekenbottle  Offline
Member

Joined: Oct 2008
Posts: 218
Nashua NH
Using c_move will manipulate the player model by displacing him along his own origin rather than the world origin, when using the relative distance vector.

What this means is, if he's facing left, he'll go left.

It is simple.

First a vector and a variable:

Code:
#define speedx skill40
#define speedy skill41  //even if you don't use skill41 and skill42
#define speedz skill42  //define them anyways so you don't accidently use them elsewhere

var velocity = 5;


I like to use skills for this vector. And I like to use velocity as a global variable so I can change it at run time to find a speed that suits me.

Now we need an action to put on our model:

Code:
#define health skill1

action moveMe()
{
   my.health = 100;
   while(my.health > 0)
   {
      wait(1);
   }
}


In most games, you can only move when alive, so I've set it up like this.

Now we need him to respond to keyboard inputs. Each key on the keyboard corresponds to a variable defined in the engine. If the key is pressed, the respective variable is 1, other wiseit is zero. And so from this, we get an equation, which does not need if-branches, and thus is shorter code than some other examples I've seen on the web.

The equation is as follows:

my.speedx = velocity * (key_w - key_s);

The way this works (remember velocity is set to 5):
If w is pressed:
my.speedx = 5 * (1 - 0) = 5 * 1 = 5 //forward movement
If s is pressed:
my.speedx = 5 * (0 - 1) = 5 * -1 = -5 //backward movement
If both are pressed:
my.speedx = 5 * (1 - 1) = 5 * 0 = 0 // no movement
If neither are pressed:
my.speedx = 5 * (0 - 0) = 5 * 0 = 0 // no movement

Now we apply the same equation to pan, except with A and D, and then plug the vector into c_move():
Code:
action moveMe()
{
   my.health = 100;
   while(my.health > 0)
   {
      my.pan = 5 * (key_a - key_d) * time_step;
      my.speedx = 5 * (key_w - key_s) * time_step;
      c_move(my,my.speedx,nullvector,IGNORE_PASSABLE | GLIDE);
      wait(1);
   }
}


And voila, a very simple movement code, that walks the player in the direction he faces.

Note, I added time_step to the action, so he walks the same speed, regardless of FPS.

since my.speedx is being treated as a vector, my.speedy and my.speedz (skills 41 and 42) are also being modified by c_move, so my.speedy can be used for strafing and my.speedz can be used for jumping/gravity.

Note the two vector parameters in c_move. The first one is relative distance. Think of it as driving a car. This means that while you may turn from going north to going south, you are still going forward relative to the car. Relative uses the model origin.

The absolute distance vector is the opposite. Imagine the car hitting a rock and flipping upside down. Now if the car fell down according to its origin, with c_move, it would fall up. But if you use the absolute distance vector, it falls down, according to the world origin, and not the car's origin.


I was once Anonymous_Alcoholic.

Code Breakpoint;
Re: Player walk the way they are facing [Re: heinekenbottle] #248497
01/27/09 08:17
01/27/09 08:17
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
basically, use relative force instead of global force with c_move.


3333333333
Re: Player walk the way they are facing [Re: Quad] #248514
01/27/09 11:02
01/27/09 11:02
Joined: May 2008
Posts: 331
Lithuania, Vilnius
Jaxas Offline
Senior Member
Jaxas  Offline
Senior Member

Joined: May 2008
Posts: 331
Lithuania, Vilnius
it's very simple:

c_move (my, vector(move_x, 0, 0), nullvector, GLIDE);

//////////////////////////////
move_x define moving speed.


The smaller the bug, the harder it is to kill.
_________________________________________
Forklift DEMO (3dgs)

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

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