Disabling diagonal movement

Game Editor comments and discussion.

Disabling diagonal movement

Postby Totter » Tue Aug 26, 2008 1:45 pm

Hey guys,

I'm working on an RPG character and I can get him to move up, down, left, and right just fine, but whenever I have two of those buttons pressed he moves diagonal, which I want to stop. Also, when I stop pressing one of those buttons he performs the "key up" change animation (which is a standing animation) but he continues moving in the direction of the button that is still being pressed.

Any idea of how to fix this?
Working on learning GE - would like to finally create my RPG: Survivors of Atlan; and my platforming game: X3n0s - Viral Infection

http://gamedesignandarchitecture.blogspot.com - thesis blog

http://tipher.deviantart.com - DeviantArt page
User avatar
Totter
 
Posts: 19
Joined: Wed Jul 02, 2008 10:54 pm
Score: 0 Give a positive score

Re: Disabling diagonal movement

Postby Thanx » Tue Aug 26, 2008 2:01 pm

Hmmm, all the movement problems you can have!!! :D :lol: hahaha
To disable diagonal movement, just do this; in Keydownevent of one of the the arrows: add an EventDisable for the other key downs, and in the key up, the EventEnable for the other key downs of the arrows. That'll solve it all right there!
http://www.youtube.com/watch?v=XyXexDJBv58
http://www.youtube.com/watch?v=Be4__gww1xQ
These are me and playing the piano (second one with a friend/fellow student)
Hope you watch and enjoy!
User avatar
Thanx
 
Posts: 314
Joined: Sat Jan 26, 2008 10:07 pm
Location: Home sweet home! :)
Score: 24 Give a positive score

Re: Disabling diagonal movement

Postby Thanx » Tue Aug 26, 2008 2:03 pm

An for each key down of the other arrows, also disable and enable their Key up events too, to stop the animation problem...
http://www.youtube.com/watch?v=XyXexDJBv58
http://www.youtube.com/watch?v=Be4__gww1xQ
These are me and playing the piano (second one with a friend/fellow student)
Hope you watch and enjoy!
User avatar
Thanx
 
Posts: 314
Joined: Sat Jan 26, 2008 10:07 pm
Location: Home sweet home! :)
Score: 24 Give a positive score

Re: Disabling diagonal movement

Postby Totter » Tue Aug 26, 2008 3:16 pm

Cool, thanks!

I tried to put it together, but I seem to be having some trouble just adding the events. I am trying to script what you described in the script editor so I'm wondering what the script would be for this...
Working on learning GE - would like to finally create my RPG: Survivors of Atlan; and my platforming game: X3n0s - Viral Infection

http://gamedesignandarchitecture.blogspot.com - thesis blog

http://tipher.deviantart.com - DeviantArt page
User avatar
Totter
 
Posts: 19
Joined: Wed Jul 02, 2008 10:54 pm
Score: 0 Give a positive score

Re: Disabling diagonal movement

Postby Thanx » Tue Aug 26, 2008 4:19 pm

When in the script editor, click on "variables/functions" and look up the EventEnable, and EventDisable functions, from the functions, and from there you can figure it out, I think
http://www.youtube.com/watch?v=XyXexDJBv58
http://www.youtube.com/watch?v=Be4__gww1xQ
These are me and playing the piano (second one with a friend/fellow student)
Hope you watch and enjoy!
User avatar
Thanx
 
Posts: 314
Joined: Sat Jan 26, 2008 10:07 pm
Location: Home sweet home! :)
Score: 24 Give a positive score

Re: Disabling diagonal movement

Postby Totter » Tue Aug 26, 2008 4:46 pm

Okay...I can find the event disable script, but I need to know how to do it for the other arrow keydowns and not all keydowns
Working on learning GE - would like to finally create my RPG: Survivors of Atlan; and my platforming game: X3n0s - Viral Infection

http://gamedesignandarchitecture.blogspot.com - thesis blog

http://tipher.deviantart.com - DeviantArt page
User avatar
Totter
 
Posts: 19
Joined: Wed Jul 02, 2008 10:54 pm
Score: 0 Give a positive score

Re: Disabling diagonal movement

Postby Thanx » Wed Aug 27, 2008 6:41 pm

Ok, after some thinking I came up with another idea.
Create an "akeydown" variable.
First of all. If no key is down, we'll have this be 0. If the up key is down (or w or whatever takes the character upwards) it'll be 1, for right it'll be 2, for down it'll be 3, for left it'll be 4. In the code I'm giving, I'm gona mark these 1-4 numbers as dirnum standing for DIRection NUMber, but you use the apropriate numbers I have listed now. Now in the first 3 lines add these:
if(akeydown == 0 || akeydown == dirnum)
{
akeydown = dirnum;

In the line after the last in current code, add this one line:
}
Do this with all you key down codes for the movement, if you haven't yet.
Open the key up events, and add these lines in as the first 3, again the dirnum indicating the apropriate number.:
if(akeydown == dirnum)
{
akeydown = 0;
And again add a "}" behind all the code.
I think that's it now! :wink:
http://www.youtube.com/watch?v=XyXexDJBv58
http://www.youtube.com/watch?v=Be4__gww1xQ
These are me and playing the piano (second one with a friend/fellow student)
Hope you watch and enjoy!
User avatar
Thanx
 
Posts: 314
Joined: Sat Jan 26, 2008 10:07 pm
Location: Home sweet home! :)
Score: 24 Give a positive score

Re: Disabling diagonal movement

Postby Totter » Thu Aug 28, 2008 6:32 pm

Thanx wrote:Ok, after some thinking I came up with another idea.
Create an "akeydown" variable.
First of all. If no key is down, we'll have this be 0. If the up key is down (or w or whatever takes the character upwards) it'll be 1, for right it'll be 2, for down it'll be 3, for left it'll be 4. In the code I'm giving, I'm gona mark these 1-4 numbers as dirnum standing for DIRection NUMber, but you use the apropriate numbers I have listed now. Now in the first 3 lines add these:
if(akeydown == 0 || akeydown == dirnum)
{
akeydown = dirnum;

In the line after the last in current code, add this one line:
}
Do this with all you key down codes for the movement, if you haven't yet.
Open the key up events, and add these lines in as the first 3, again the dirnum indicating the apropriate number.:
if(akeydown == dirnum)
{
akeydown = 0;
And again add a "}" behind all the code.
I think that's it now! :wink:


I really hate to come off as an idiot...but I'm not really familiar with programming so is there a good tutorial for creating a variable like this? I put all these values into the actions like you described but it didn't do anything, and I created the variable (as best I knew) but I don't understand how this links to what is typed into the actions...
Working on learning GE - would like to finally create my RPG: Survivors of Atlan; and my platforming game: X3n0s - Viral Infection

http://gamedesignandarchitecture.blogspot.com - thesis blog

http://tipher.deviantart.com - DeviantArt page
User avatar
Totter
 
Posts: 19
Joined: Wed Jul 02, 2008 10:54 pm
Score: 0 Give a positive score

Re: Disabling diagonal movement

Postby AoiYuurei » Thu Aug 28, 2008 11:02 pm

Hi, I know I'm new and what not and I know I'm not great with C or scripting. I do however read and get ideas and learn from reading other problems and solutions. I was working on this myself and have a working ged of this, though bear in mind the variables are differently named etc. I also used an already made sprite (just an easy way to test), the sprite will walk in all 4 directions (up, down, left, right) with changing animations, and has the wire-frame boxes to move the screen around when walking. I'm hopefully going to work on making an RPG type game... but anyway, you're welcome to it (hopefully to the other more knowledgeable it is up to snuff):

http://ifile.it/hr0ayxk

Edit: The code I used....

I created 2 global variables: 'canmove' and 'inmotion'. As explained, using a number for each direction ( 1, 2, 3, 4 for down, right, left, up) and setting the direction number to 'inmotion' when in use. So when I press the 'down' key, 'inmotion' is set to 1. For any other direction key, if 'inmotion' is not equal to 0, it will not tell it to move.

On Key Down event:
Code: Select all
if (canmove == 0 && inmotion == 0) {
yvelocity = 4;
inmotion = 1;
ChangeAnimation("Mog", "Mog - Walk (Front)", FORWARD);
                  }


Now, put the code for the key-up event; this is going to reset the 'inmotion' variable when you're finished pressing the 'down' key. Once you lift your finger off of the 'down' key, 'inmotion' is now set to 0. Now you can use another direction key.

On Key Up event:
Code: Select all
if (inmotion == 1) {
    yvelocity = 0;
    inmotion = 0;
ChangeAnimation("Mog", "Mog (Front)", FORWARD);
                  }


Just remember, you have to create these events on each direction key. Make sure each key-down event has the appropriate key-up event (8 events total), you wouldn't want to have the 'right' key's key-up event on the 'left' key's key-up event, as you wouldn't be able to stop your character until you press and release the 'left' key. ^_~

I do not have the 'canmove' in the key up event, as it should be controlled by another event. Like talking with an NPC, have an event setting the 'canmove' variable to 1 or any other number, while you are talking to it. Once that event is finished, you should reset 'canmove' back to 0 to allow your character to move again. Sorry I didn't include any events that show this, in the ged file.

I hope that was clear and easy enough to unedrstand ^^;
AoiYuurei
 
Posts: 1
Joined: Wed Apr 23, 2008 10:38 am
Score: 0 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron