Moving problem

Non-platform specific questions.

Moving problem

Postby AleX_XelA » Mon Mar 06, 2006 9:10 pm

Hi folks!

As you can see, I'm completely new to Game-Editor, and discovered it thanks to a friend of mine. The tool is amazing, and I am learning C at the moment, which helps me a lot in the development of my games. Although I have a problem, and it's a problem that also appears on the "Caveman" game.
If I move to the right and suddenly press left (without releasing right), the player actor stops but if I release the left key, the animation changes to the "stop left" one and it moves to the right. Is there a way to avoid this? Thanks for your answers!
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Postby Novice » Mon Mar 06, 2006 10:24 pm

I would also like to know if anyone found out an easy way to stop this. The only way that works for me is using key up events so for ex. right key is released and on key up check if the left key is still pressed if it is pressed change the actor animation to left actor anim. and so on... the only problem for this solution is that you have to cover all the possibilities, which can be a bit of a hassle when you use five buttons in your game. The other way would be to disallowe the user to press multiple keys at once, but i think that this would interfere with the gameplay and would be annoying.
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby DilloDude » Tue Mar 07, 2006 12:40 am

You can use variables. Have a variable for 'moving' and a variable for 'direction'. On the left key down, moving = 1, direction = 0. On right key down, moving = 1, direction = 1. On key up for left or right, moving=0. On draw actror, if moving, if direction==1, x+=3, if animindex != the index for moving right, change animation to moveright. Then under the direction 'if', else if direction==0, x-=3, if animindex != the index for moving left, change animation to moveleft. Back under the moving 'if', else, if direction == 1, change animation to stopright, else if direction ==0, change animation to stopleft.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby AleX_XelA » Tue Mar 07, 2006 4:04 pm

Wow, I didn't get the complete post you made there DilloDude, can you post just one big chunk of code? Oh and if you could comment it, it would make it easier for me to understand! Thanks in advance!
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Postby AleX_XelA » Tue Mar 07, 2006 9:52 pm

Well I kinda figured out a way of doing it, I'll post my code :
Code: Select all
char *key = GetKeyState(); //Get entire keyboard state
 int facing = 0; //Determines facing, 1 = right ; 2 = left ; 3 = up ; 4 = down.
 int moving = 0;
 

if(key[KEY_RIGHT] == 1) //Test if right key is pressed
{
x = x + 2; //Move actor to right
facing = 1;
moving = 1;
}

if(key[KEY_LEFT] == 1) //Test if left key is pressed
{
x = x - 2; //Move actor to left
facing = 2;
moving = 1;
}
 if(key[KEY_UP] == 1) //Test if up key is pressed
 {
     y = y - 2; //Move actor to up
     facing = 3;
     moving = 1;
 }
 if(key[KEY_DOWN] == 1) //Test if down key is pressed
 {
     y = y + 2; //Move actor to down
     facing = 4;
     moving = 1;
 }

 if(key[KEY_RIGHT] == 1 && key[KEY_LEFT] == 1 && facing == 1) //Test if right and left key are pressed
 {
     x = x + 0; //Stop actor
     ChangeAnimation("Event Actor", "stop_right", FORWARD);
 }
 if(key[KEY_RIGHT] == 1 && key[KEY_LEFT] == 1 && facing == 2) //Test if right and left key are pressed
 {
     x = x + 0; //Stop actor
     ChangeAnimation("Event Actor", "stop_left", FORWARD);
 }
if(key[KEY_DOWN] == 1 && key[KEY_UP] == 1 && facing == 3) //Test if up and down key are pressed
 {
     y = y + 0; //Stop actor
     ChangeAnimation("Event Actor", "stop_up", FORWARD);
 }
 if(key[KEY_DOWN] == 1 && key[KEY_UP] == 1 && facing == 4) //Test if up and down key are pressed
 {
     y = y + 0; //Stop actor
     ChangeAnimation("Event Actor", "stop_down", FORWARD);
 }

if (facing == 1 && moving == 1 && animindex != 6 && animindex != 2) //Makes sure the running sprite is always correct depending on the facing of the actor
{
    ChangeAnimation("Event Actor", "run_right", FORWARD);
}

if (facing == 2 && moving == 1 && animindex != 5 && animindex != 1)
{
ChangeAnimation("Event Actor", "run_left", FORWARD);
}

if(facing == 3 && moving == 1 && animindex != 7 && animindex != 3)
{
    ChangeAnimation("Event Actor", "run_up", FORWARD);
}

if(facing == 4 && moving == 1 && animindex != 4 && animindex != 0)
{
ChangeAnimation("Event Actor", "run_down", FORWARD);
}


So this works but only for going left and down. If I go left and press right at the same time, the actor will stop and the animation will be "stop left". Same thing for pressing down and up. BUT if I go up and press down at the same time, the sprite will change to "stop down" instead of "stop up". I get the same thing with going right. I've checked my code three times, and I can't make out how this can happen... Anyone wants to help me?

BTW this is in the Draw Actor section. The Key Down and Key Up buttons for changing the animations into the running ones are already done aside from this code.
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Postby AleX_XelA » Wed Mar 08, 2006 7:11 pm

The user-forum is highly active, friendly and useful when you need help.

Quoted from the Game Editor reminder message.

I really thought you guys would help me, I'm sure it's just a small glitch, please! My trial version is for only one month, and I haven't even completed a decent walking engine.
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Postby makslane » Thu Mar 09, 2006 5:31 pm

Look this solution for the sliding problem:

player -> Key Down (left, repeat):

Code: Select all
x -= 5;


player -> Key Down (right, repeat):

Code: Select all
x += 5;


player -> Draw Actor

Code: Select all
if(last_xvelocity != xvelocity) //Create the last_xvelocity as Real in the Variables panel
{
  if(xvelocity < 0) ChangeAnimation("Event Actor", "Left", FORWARD);
  else if(xvelocity > 0) ChangeAnimation("Event Actor", "Right", FORWARD);
  else
  {
      //Stopped
      if(last_xvelocity < 0) ChangeAnimation("Event Actor", "Stop Left", FORWARD);
      else if(last_xvelocity > 0) ChangeAnimation("Event Actor", "Stop Right", FORWARD);
  }

  last_xvelocity = xvelocity;
}


Download sample at:
http://game-editor.com/examples/avoidin ... _slide.zip
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby AleX_XelA » Thu Mar 09, 2006 5:39 pm

A reply from the creator himself! I didn't expect that! Sadly, you are having the same trouble as me, when I run left and suddenly press right (without releasing left), the character pose changes to "stop right", but it should change to "stop left"!
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Postby AleX_XelA » Sun Mar 12, 2006 8:08 pm

Don't tell me no one has managed to do a proper walking engine? Please help me guys!
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Postby AleX_XelA » Mon Mar 13, 2006 8:57 pm

Well I'm giving up on this, Game Editor doesn't seem to fill my needs. It can't even provide me a proper walking engine! How would a game work if you can't even walk properly in it!
I'm ready to give GE a second chance if someone finds a way of fixing my code :
Zelda Engine by AleX : ZIP file, contains code + Windows EXE.

Here are the glitches :
- If you go up and press down without releasing up, the sprite will change to "stop_down" instead of "stop_up".
- Same for running right.

Those glitches don't appear for going left and going down, I don't have the gliding glitch anymore! But I still don't understand why it does me those 2 glitches... Please can someone help me fix them!
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Postby makslane » Mon Mar 13, 2006 9:40 pm

What should be the correct behavior when left and right keys are pressed (first left):
Stop or go to right?
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby AleX_XelA » Mon Mar 13, 2006 9:49 pm

The correct behavior for what you said should be "stop_left" (because you pressed left first). I did make that on my engine, but couldn't manage to make it work for the 4 directions, only 2 of them work :
Left first
and
Down first.
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Postby Novice » Wed Mar 15, 2006 11:46 am

Ok i finaly solved this problem, it's not that complex it just requres a lot of typing or in your case copying and pasting :wink:. Note that this will make your character go only up, down, left and right, but that can easily be changed to more animations just follow the patern in wich this was done.
For all others who had this problem, for this to work properly your animations have to be called: run_right, run_up... stop_left, stop_down or change the code but i think the first option is faster.

Now il explain how this code works.

Draw Actor-Script Editor
Code: Select all
char *key=GetKeyState();

if
(key[KEY_UP]==1&&key[KEY_DOWN]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0) y-=2;
else if (key[KEY_UP]==0&&key[KEY_DOWN]==1&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0) y+=2;
else if (key[KEY_UP]==0&&key[KEY_DOWN]==0&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==0) x-=2;
else if (key[KEY_UP]==0&&key[KEY_DOWN]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==1) x+=2;

This checks wich keys are pressed at all times and moves or stops the actor acorrdingly.

Key Down(Left)-Script Editor(Repeat:Disable, At least one key is pressed)
Code: Select all
char *key=GetKeyState();


if (key[KEY_UP]==0&&key[KEY_RIGHT]==0&&key[KEY_DOWN]==0)
ChangeAnimation("Event Actor", "run_left", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_RIGHT]==0&&key[KEY_DOWN]==0)
ChangeAnimation("Event Actor", "stop_up", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_RIGHT]==1&&key[KEY_DOWN]==0)
ChangeAnimation("Event Actor", "stop_right", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_RIGHT]==0&&key[KEY_DOWN]==1)
ChangeAnimation("Event Actor", "stop_down", FORWARD);

This code checks wich keys are already pressed when you press a new key, then it stops the actor facing the way he was facing before the key was pressed. This code is simillar for all key down events but requires modifiying so il just post it and make it easier for all of you.

Key Down(Right)-Script Editor(Repeat:Disable, At least one key is pressed)
Code: Select all
char *key=GetKeyState();

if (key[KEY_UP]==0&&key[KEY_LEFT]==0&&key[KEY_DOWN]==0)
ChangeAnimation("Event Actor", "run_right", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_LEFT]==0&&key[KEY_DOWN]==0)
ChangeAnimation("Event Actor", "stop_up", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_LEFT]==1&&key[KEY_DOWN]==0)
ChangeAnimation("Event Actor", "stop_left", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_LEFT]==0&&key[KEY_DOWN]==1)
ChangeAnimation("Event Actor", "stop_down", FORWARD);


Key Down(Down)-Script Editor(Repeat:Disable, At least one key is pressed)
Code: Select all
char *key=GetKeyState();


if (key[KEY_UP]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_down", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_up", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_left", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "stop_right", FORWARD);

Key Down(Up)-Script Editor(Repeat:Disable, At least one key is pressed)
Code: Select all
char *key=GetKeyState();


if (key[KEY_DOWN]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_up", FORWARD);
else if (key[KEY_DOWN]==1&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_down", FORWARD);
else if (key[KEY_DOWN]==0&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_left", FORWARD);
else if (key[KEY_DOWN]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "stop_right", FORWARD);


Now we come to the key up events wich check wich keys are pressed when you release a key and changes the animation accordingly.

Key Up(Left)-Script Editor
Code: Select all
char *key=GetKeyState();


if (key[KEY_UP]==0&&key[KEY_DOWN]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_left", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_DOWN]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_up", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_DOWN]==1&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_down", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_DOWN]==0&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "run_right", FORWARD);


Key Up(Right)-Script Editor
Code: Select all
char *key=GetKeyState();


if (key[KEY_UP]==0&&key[KEY_DOWN]==0&&key[KEY_LEFT]==0)
ChangeAnimation("Event Actor", "stop_right", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_DOWN]==0&&key[KEY_LEFT]==0)
ChangeAnimation("Event Actor", "run_up", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_DOWN]==1&&key[KEY_LEFT]==0)
ChangeAnimation("Event Actor", "run_down", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_DOWN]==0&&key[KEY_LEFT]==1)
ChangeAnimation("Event Actor", "run_left", FORWARD);


Key Up(Down)-Script Editor
Code: Select all
char *key=GetKeyState();


if (key[KEY_UP]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_down", FORWARD);
else if (key[KEY_UP]==1&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_up", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_left", FORWARD);
else if (key[KEY_UP]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "run_right", FORWARD);

Key Up(Up)-Script Editor
Code: Select all
char *key=GetKeyState();


if (key[KEY_DOWN]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "stop_up", FORWARD);
else if (key[KEY_DOWN]==1&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_down", FORWARD);
else if (key[KEY_DOWN]==0&&key[KEY_LEFT]==1&&key[KEY_RIGHT]==0)
ChangeAnimation("Event Actor", "run_left", FORWARD);
else if (key[KEY_DOWN]==0&&key[KEY_LEFT]==0&&key[KEY_RIGHT]==1)
ChangeAnimation("Event Actor", "run_right", FORWARD);


And thats it just copy and paste it and you should have no problem. I'm sure that there are much faster and better ways to do this and if you know one please share it with us.
Hope this helps everyone who had this problem (almost everybody, including me) and i hope that there will be a way to do this faster in next versions of GE.
Alex_XelA wrote:
The user-forum is highly active, friendly and useful when you need help.


Quoted from the Game Editor reminder message.

I really thought you guys would help me, I'm sure it's just a small glitch, please! My trial version is for only one month, and I haven't even completed a decent walking engine.

We are helpful, just give us some time :wink: my internet connection was dead a few days so i couldn't help.
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby plinydogg » Wed Mar 15, 2006 1:49 pm

Alex_Xela,

Didn't you read the GE system requirements carefully before downloading the demo? "System requirements: Windows (95, 98, Me, NT, 2000, 2003, XP) and at least a modicum of patience"

Just kidding (sort of). But in all seriousness, Novice is right: the community here is pretty supportive and helpful...even if they don't answer your questions minutes after you ask them.

And for what it's worth, people might be more willing to help you if you didn't sound so...well...snotty. Instead of saying "It [GE] can't even provide me a proper walking engine!," why don't you be more correct and say "I don't know how to make GE provide me a proper walking engine!"

No offense.
plinydogg
 
Posts: 104
Joined: Thu Aug 25, 2005 8:34 pm
Score: 0 Give a positive score

Postby AleX_XelA » Wed Mar 15, 2006 3:20 pm

Thanks for your reply Novice! I'm going to try that out now! Although your code seems too repetitive, I'm sure we can find a way to optimize it!

plinydogg -> No offence taken, but when you download a demo from the home page that does not work correctly, and that was made from the creator himself, you can doubt the program's power. Although I'll make sure to post new topics when I really cannot find a way of doing it!

EDIT : It works perfectly well! Thanks a lot Novice, I'll try to see if I can find a shorter way of doing it, and I'll keep you all updated!
AleX_XelA
 
Posts: 28
Joined: Mon Mar 06, 2006 9:04 pm
Score: 0 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest