Page 1 of 1

Basic Beginner Questions

PostPosted: Thu Aug 04, 2011 5:05 pm
by BS87
Hey guys,

for a course on my university I have to create a small game until end of August (not that much time, I know). Since I'm new to programming and Game Creation, I decided to give Game Editor a shot, since it looked pretty easy to get into.
I worked through some of the basic tutorials, drew some sprites and now got a basic scenario with a character and platforms made of tiles. The character is able to move to the left and right and jump. Now I'm already starting to get some "bugs" and need your help to remove them before I go on to the more advanced stuff (will create another thread when I'm further into delevopment then). But simple things first:

1. The character is able to repeat jumps in mid-air (already switched the repeat function for the button down to off, which avoids keeping the button pressed to "fly"). How am I able to tell the program that he only is capable to jump while standing on the floor?
2. As I said, I used the basic tutorial for creating gravity and letting the character jump (using the yvelocity values), but now he tends to randomly fall through the floor and moreover has no hit detection if he walks into walls (falls right through them) or hits them from below. How to fix that?
3. Strangely I don't have encountered the, as you seem to call it on this board, "moonwalk"-problem yet, but the walking animation seems to be faster and choppier than previewed in the small animation window. I guess this has to do with keeping the left/right button pressed and the animation is always repeated then. I also used the "button up"-command to switch back into the idle animation as soon as you stop walking, is this the correct way to do it or will I encounter bugs with that?

Would be very happy to get some help of you "professionals" :) Thanks in advance!
BS87

Re: Basic Beginner Questions

PostPosted: Thu Aug 04, 2011 5:53 pm
by Game A Gogo
Hello to the forums!

Game Editor is in my opinion, indeed the tool of choice for your solution. Seems like you're making a platformer jump & run.

Here's a little demo I made: viewtopic.php?f=6&t=9992 which involves bugless collision

now if you want to make your game the same way as this demo, note you won't be able to have top collision only platforms, as this would require special actor checking that would break the features found with the function "CollisionFree" so you'll notice this demo uses a totally different approach, thus might be too complicated yet if you're new to programming as you say.

So if you're going to stay with your method here are a few tricks:

I assume you are using PhysicalResponse when you are colliding with you ground actor, make the collision event is set to repeat (A little button that says no by default that should be changed to yes)

For your jumping problem, creating a variable in this effect would be preferred. You can create one in the Variables dialog when a script is opened, name it CanJump.
for jumping I suspect you have something like
Code: Select all
yvelocity=yvelocity-5;
or the like
you want to the player only to jump when CanJump is set to 1... you can make that with an if statement
Code: Select all
if(CanJump)// if checks if the given value is equal to TRUE, or in other words anything greater than 0
{                          // you can use things like ==, >=, <=, <, >,!=, but we will not use them here...
    yvelocity-=5;//why -= you might ask, this will tell us to subtract the given amount from the variable
    CanJump=0;//We don't want him jumping again!
}

Now you need the event that allows the player to jump... which one? simple, the one with the physical response!
so your collision script (with Repeat on!) should look like this:
Code: Select all
PhysicalResponse("Event Actor","Collide Actor",1,1,0,0);
CanJump=1;//You can jump my friend! Jump to victory!   ... or that coin over there too :)


For anti moonwalk... well since you have no problem with it, I'll leave you with this: viewtopic.php?f=4&t=8844&p=61578&hilit=moonwalk#p61578

Re: Basic Beginner Questions

PostPosted: Fri Aug 05, 2011 3:15 pm
by BS87
Hey Game A Gogo, thanks for the quick help! The trick with turning repeating in PhysicalResponse on to avoid characters falling to the floor worked flawless.
For the coding, however, I'm still a bit too green it seems. Where exactly do I have to create the variable (in the button down event?) and which settings do I need for it (theres a dialog coming up if you create a new variable in the script editor)?
Moreover I wasn't able to open the script editor in the collision event (no button available there somehow) to type in the last piece of code you gave me.

Thanks in advance!
BS87

EDIT: Just found out that there are several more text tutorials on your homepage (which include the canjump script), which I probably should go through first before asking more questions, sorry about that, only saw the tutorials IN game editor. However, I just encountered a new glitch: The characters seem to be able to slide up walls if you walk into them now. Any ways to fix that?

Re: Basic Beginner Questions

PostPosted: Fri Aug 05, 2011 4:41 pm
by foleyjo
Are you using the same actor for your wall as the floor?

If so you could make it so the physical response only happens if your actor is falling down. if(yvelocity >0) {physical....}

Re: Basic Beginner Questions

PostPosted: Fri Aug 05, 2011 5:54 pm
by Game A Gogo
to create a variable, you can either open up the global code editor or any script, then click on the Variables button, there you can create a new variable, all the defaults setting should be fine on it.a

But since words often get the better of me instead of me explaining myself correctly, I'll use an image!
Image

when adding your collision event, it should be something like this:

Image

Re: Basic Beginner Questions

PostPosted: Fri Aug 05, 2011 6:08 pm
by lcl
Game A Gogo wrote:For anti moonwalk... well since you have no problem with it...

Actually, he has, it keeps repeating the animations first few frames because the animation starts from beginning every frame when key is pressed. I know that because I had the same with my first game. :D

Anyway, GAG, maybe something simpler is better for a beginner. :wink:

Re: Basic Beginner Questions

PostPosted: Fri Aug 05, 2011 7:00 pm
by Game A Gogo
Well then... here is one of the best way to have anti-moonwalk, in my opinion:

You probably have the changeanimations in the keyup and and keydown events right?
I want you to remove them, all. But make sure to leave the movement code!

What creates moonwalk or abnormal animations, is the sequence of the change animations. That means the animation shouldn't be changed depending on what key is pressed.
But on what could animation change be affected by? Very simple actually! xvelocity and yvelocity! Animation should be based on what the actor IS doing and not what it SHOULD be doing ;)

Now I presented the concept, here's how to put it to work!

We'll need to check if our player is standing, what direction he's facing, if he's moving and if he's jumping. Although if you have no jumping animations, you simply check if he's moving and what direction he's facing...
And when should we check these conditions? in draw actor!

But before you start scripting, you need to create a variable that will hold the last direction of the player, 0 will mean Right, 1 will mean Left. Only because something tells me your player will by default point to the right :)
Name this variable something like "P_Dir" or even just "Dir" if you don't want to get sophisticated like me, default settings for this one will be fine.
And we also need another variable, but this time, instead of being an Integer, it should be a Real one, it should be the main dropdown box in the dialog.
Name this variable "Sensitivity", it will be for adjusting the smoothness of your animation, you'll probably need to tweak this one.
We need to have this variable set to a value, so you'll need a "Create Actor" event and add a script like this:
Code: Select all
Sensitivity=0.4;//Remember to tweak this code to your preference!
//A value near 0 will make it too sensitive
//A value greater than your walking speed will make him always standing
//A value in the negative might make him always walk


now in the draw actor event, here's what a script should look like if you only had moving animations and stopped animations (no jumping/falling animations)
Code: Select all
//First we need to check  what direction the player last moved towards to
if(xvelocity>Sensitivity)//The player is moving to the right, his xvelocity is greater
{
    Dir=0;//The player is facing right :)
}
else if(xvelocity<-Sensitivity)//The player is moving to the left, his xvelocity is lesser, we also use else here to remove any CPU load when we can, for good practice :)
{
    Dir=1;//The player is facing left :)
}
//Now we can check if he's walking or not!
if(xvelocity<=Sensitivity && xvelocity>=-Sensitivity)//the && is AND and allows us to make more than one condition check
{//if the player is not moving, he surely be near 0 xvelocity if not 0
    switch(Dir)//Switch allows us to give action depending on what the value the variable is, this simply saves us time!
    {
        case 0: //if Dir is 0, or facing right
        ChangeAnimation("Event Actor","Stand_Right",NO_CHANGE);//make sure to change the names, we also use NO_CHANGE so the animation doesn't constantly repeats itself
        break; //Prevents the code from executing further... otherwise it will run what's below
        case 1://if Dir is 1, or facing left
        ChangeAnimation("Event Actor","Stand_Left",NO_CHANGE);//Again, make sure to change the names
        break;//Never forget these in your switch statement!
    }
}
else //Obviously, if the player is not not moving, then he must be moving! ;) so here is what happens otherwise!
{
    switch(Dir)//Again, we need to know which direction he's walking!
    {
        case 0: //seems to me he's walking right!
        ChangeAnimation("Event Actor","Walk_Right",NO_CHANGE);//Also don't forget the NO_CHANGE, and to change the names!
        break;
        case 1: //walking left...
        ChangeAnimation("Event Actor","Walk_Left",NO_CHANGE);//To change the names, forget not you should.
        break;//Neither these!
    }
}
//Seems to me we're done here ;)


Now that should be it.

But if you happen to have falling and jumping animation, that just means one more condition check!
here's how it'd look! I'll omit commenting on places that are the same...

Code: Select all
if(xvelocity>Sensitivity)
{
    Dir=0;
}
else if(xvelocity<-Sensitivity)
{
    Dir=1;
}

if(yvelocity>Sensitivity)//When player falls, his yvelocity is greater :)
{
    switch(Dir)
    {
        case 0:
        ChangeAnimation("Event Actor","Fall_Right",NO_CHANGE);
        break;
        case 1:
        ChangeAnimation("Event Actor","Fall_Left",NO_CHANGE);
        break;
    }
}
else if(yvelocity<-Sensitivity)//When player jumps, his yvelocity it lesser!
{
    switch(Dir)
    {
        case 0:
        ChangeAnimation("Event Actor","Jump_Right",NO_CHANGE);
        break;
        case 1:
        ChangeAnimation("Event Actor","Jump_Left",NO_CHANGE);
        break;
    }
}
else//If player is not jumping or falling... he must be standing :)
{
    if(xvelocity<=Sensitivity && xvelocity>=-Sensitivity)
    {
        switch(Dir)
        {
            case 0:
            ChangeAnimation("Event Actor","Stand_Right",NO_CHANGE);
            break;
            case 1:
            ChangeAnimation("Event Actor","Stand_Left",NO_CHANGE);
            break;
        }
    }
    else
    {
        switch(Dir)
        {
            case 0:
            ChangeAnimation("Event Actor","Walk_Right",NO_CHANGE);
            break;
            case 1:
            ChangeAnimation("Event Actor","Walk_Left",NO_CHANGE);
            break;
        }
    }
}
//Done again :D


Hopefully you understand any of this... and that it helped!

Re: Basic Beginner Questions

PostPosted: Fri Aug 05, 2011 7:03 pm
by lcl
Got to say: Thank you GAG for helping him. :D
I didn't have time to help but I saw what he needs help with, so thanks
to you for helping him! :)

Re: Basic Beginner Questions

PostPosted: Fri Aug 05, 2011 7:11 pm
by Game A Gogo
Well hopefully if this helps him. I'm sure it's a bit more readable in GE, for the comments

Re: Basic Beginner Questions

PostPosted: Fri Aug 05, 2011 9:06 pm
by BS87
Whew, so many replies! Thank you guys very, very much for giving up so much of your time for me! Since it's a bit late I'm going to continue my game tomorrow and will report back (and maybe upload the current version) tomorrow. Thanks again! :D

Re: Basic Beginner Questions

PostPosted: Sun Aug 07, 2011 2:38 pm
by BS87
Hey guys, I'm back and after some error messages (yes, I actually got some typos in that short code) and fumbling around I actually managed to get rid of double jumping (for both characters, as I created two canjump variables since they obviously fucked themselves up if one character was airborne and the other one tried to jump). The only physics problem left now is the vertical wall collision as characters can stick to walls and slide off platforms when you stand close to the edges. For better understandment and as a little thank you for your help I uploaded the current version of my game for you to "test" (you actually can only walk/jump around atm, but I want to get the basics right first).

EDIT: Seems like the file attachment doesn't work for me. Uploaded it HERE instead. By the way, controls are wasd and arrow keys (up/down to jump since I'm planning a gravity switch later (oh geez)).

Re: Basic Beginner Questions

PostPosted: Mon Aug 08, 2011 7:18 pm
by Game A Gogo
To be honest, the sticky problem is something I had a hard to time over come, implanting my custom collision system solved it but it can be hard to work with if you're not used to it...
Others have other techniques that work and still uses physical response I beleive

Re: Basic Beginner Questions

PostPosted: Mon Aug 08, 2011 8:29 pm
by skydereign
Using PhysicalResponse in most cases works fine. There is a slight workaround necessary for wall collisions, but it makes perfect sense, it just requires more collision events. So if I'm using PhysicalResponse I end up using 3 events. One for the top of the tiles (has the PhysicalResponse and changing animations back to stand if you were jumping), one for the sides (has the fix in it), and the top of the tiles (just a PhysicalResponse). So, if you want to continue using PhysicalResponse, you can use this for your wall collisions.
player -> Collision with sides of wall (repeat enabled) -> Script Editor
Code: Select all
double yvel = yvelocity;
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.00, 1.00, 0.00, 0.00);
yvelocity = yvel;