Page 1 of 1

Trying to get mario to run

PostPosted: Sun May 01, 2011 5:04 pm
by youbob1212
Ok I'm just trying to get mario to do some of the most basic things.
Like run left and right, stand left and right, and skid left and right.

I haven't get to the jump, because I haven't figure out the basics up.

There is a file uploaded.

Any help in this??

Re: Trying to get mario to run

PostPosted: Sun May 01, 2011 8:29 pm
by SuperSonic
Here ya go youbob :P
I added the skid function and fixed your code a little. If you have any questions about the code just post here or send me a PM :wink:
http://www.multiupload.com/WM4UB7AE1F
Here's the file^^

Re: Trying to get mario to run

PostPosted: Mon May 02, 2011 1:32 am
by youbob1212
That worked out great!

All I have to do is add in Gravity and we should have 80% physics of the game.

All is left is to make a tutorial on it.

Re: Trying to get mario to run

PostPosted: Mon May 02, 2011 1:33 am
by youbob1212
I mean could you tell me the steps that you took to make it all work out?

Also I worked with the Gravity issue, and it seems to be in error with the jump function.This is the post I was look at. From the very beginning.
viewtopic.php?f=4&t=8572&p=60238

Re: Trying to get mario to run

PostPosted: Mon May 02, 2011 5:18 pm
by SuperSonic
I'm not very good at explaining things but I'll give it a shot. When I explain large sections of code I'll add comments (//coment) :D
I first made a variable called PrevDir (previous direction). Then I made an event for mario like this:
Code: Select all
"create actor" -> "script editor"
PrevDir = 0

This tells the computer that his previous direction is "Right"
Then I edited the "draw actor" event for mario and did:
Code: Select all
if(PressButtonRight == 1)//this line asks if the right arrow button is up.
{
    if(xvelocity > 0)//this asks if mario's horizontal velocity is greater than zero
    {
    xvelocity = xvelocity - .5;//this slows him down
    ChangeAnimation("Event Actor", "SkidRight", FORWARD);//this makes him skid
    }
}
if(PressButtonLeft == 1)//this asks if the left arrow button is up
{
    if(xvelocity < 0)this asks if mario's horizontal velocity is less than zero
    {
    xvelocity = xvelocity + .5;//this slows him down again (remember, to slow his horizontal velocity down, you must make it closer to zero. thus by increasing "xvelocity" I am slowing him down
    ChangeAnimation("Event Actor", "SkidLeft", FORWARD);//this makes him skid again
    }
}
if(xvelocity == 0)//this asks if he is standing still
{
    if(PrevDir == 0)//this asks if he was previously facing right
    {
        ChangeAnimation("Event Actor", "StandingRight", FORWARD);//this makes him stand facing the right
    }
    else//If he was not previously facing right then..
    {
        ChangeAnimation("Event Actor", "StandingLeft", FORWARD);//...he will face left
    }
}


Then I changed his "key down Right" to this:
Code: Select all
PrevDir = 0;//this tells the computer that he is facing right
PressButtonRight = 0;//this tells the computer that the right arrow key is down
ChangeAnimation("Event Actor", "RunRight", NO_CHANGE);//this makes him run right. the "NO_CHANGE" function tells the computer to play the entire animation over and over instead of playing the first frame again and again
xvelocity=xvelocity+.5;//this makes him move

Then I did the same for "Key down Left" except everything was basically opposite:
Code: Select all
PrevDir = 1;//this tells the computer that he is facing left
PressButtonLeft = 0;//this tells the computer that the left arrow key is down
ChangeAnimation("Event Actor", "RunLeft", NO_CHANGE);//this makes him run left. the "NO_CHANGE" function tells the computer to play the entire animation over and over instead of playing the first frame again and again
xvelocity=xvelocity-.5;//this makes him move left

Finally for "key up Right" I did:
Code: Select all
PressButtonRight=1;//this tells the computer that the right key is up

and for "Key up Left" I did:
Code: Select all
PressButtonLeft=1;//This tells the computer that the left key is up

Hope that helps. Again, if you have any questions, just ask :wink: :P

Re: Trying to get mario to run

PostPosted: Mon May 02, 2011 6:35 pm
by youbob1212
VERY GOOD! THANK YOU MAN!!

Re: Trying to get mario to run

PostPosted: Mon May 02, 2011 7:26 pm
by SuperSonic
No problem :D
Mabye you can click point button now? :roll:
haha

Re: Trying to get mario to run

PostPosted: Tue May 03, 2011 11:24 pm
by youbob1212
Yep I sure have, But I have this new Problem.

Go ahead and download this version of Mario.

You know when you make Mario jump it shows a little animation of him putting his fist up to hit something.

Well this only happen with I'm pressing any one of those arrow keys.. This might look great or be ok, but I want him to show the animation any time that the spacebar is hit.

Also, I turn on Gravity, but using yvelocity++. It made Mario move so slow. How can I have some sort of gravity on while using the xvelocity factors...

Re: Trying to get mario to run

PostPosted: Thu May 05, 2011 9:00 pm
by youbob1212
Any idea on what to do.???

Re: Trying to get mario to run

PostPosted: Thu May 05, 2011 9:12 pm
by lcl
For moving actor on x axis it is better to change the x coordinate, instead of using xvelocity.
Xvelocity with gravity and physicalResponse doesn't work so well, because physicalResponse affects xvelocity.
But if you need to make him move like using xvelocity, but working better, do it this way:

1. Create global integer variable called xvel.
2. Then, where you have your xvelocity been set put xvel instead of xvelocity.
3. In mario's draw actor code write this:
Code: Select all
x += xvel;


Now, if you set xvel equal to 3, mario will move to right with speed of 3 pixels until xvel is changed to something else. :)

Re: Trying to get mario to run

PostPosted: Sat May 07, 2011 11:06 am
by youbob1212
It Still Didn't work. Mario just keeps skidding when he is not moving.. I either need more details for this solution to work. Other wise I'm fresh out of ideas at this moment.... :cry:

Blah I bet the answer is simple, but I feels like I spending way to much time trying to get mario to function right at the simplest level...

Re: Trying to get mario to run

PostPosted: Sat May 07, 2011 9:42 pm
by lcl
When you want to stop movement, write:
Code: Select all
xvel = 0;

I thoght you had done the movement already with xvelocity and you had done this also.

Anyway, I'd recommend moving mario like caveman in caveman demo of GE.
So, like this:
Key down - right, repeat: yes - script editor:
Code: Select all
x += 5;

It is simply better and easier to use.