Page 1 of 1

noob game scripting question

PostPosted: Sat Apr 21, 2007 11:04 pm
by shady7twenty4
Im workin on my first game a rip off mario side scroller just to get the hang of the program and am having some trouble makeing my character jump to a certin heigth and then fall stoping at the bottem of the view. Thanks.

hmmm....

PostPosted: Sat Apr 21, 2007 11:27 pm
by d-soldier
Phyics is the issue here... since you didn't give any information regarding how your game is currently setup, I'll start with some basics...

Make sure your player(actor) has some gravity applied to him in the DRAW ACTOR section. The script should be:
yvelocity = yvelocity + .6;
(adjust the .6 to your liking)
So long as you have something below him (something to walk on) with a collision event (to the player)/ physical response, you should have no problem there.
Regarding jumping, your player will need a "key down" event which has a script:
yvelocity = -8;
(also adjust to your liking)..
In regards to the screen, do you have your VIEW (the white box) parented to your player?

I highly reccomend loading any of the tutorial games (caveman) and playing around with them to see how and why things are setup the way they are. It was a big help for me.

PostPosted: Sun Apr 22, 2007 2:08 am
by Sgt. Sparky
jumping mistake there,
first make a variable called jump,
if you do not know how to make variables,
just click on the script button then global code,
or just in any codeing box,
and click on the variables button there,
not the variables/functions .
after you make the variable called jump
put this on the collision event with the top side of the ground,
Code: Select all
jump = 1;

and put this as his draw actor event,
Code: Select all
if(yvelocity > 2)jump = 0;

and when the key to jump is pressed use this,
Code: Select all
if(jump == 1) {
yvelocity = - 8;
jump = 0;
                              }

that way there will not be a repeated jump.

PostPosted: Sun Apr 22, 2007 12:04 pm
by shady7twenty4
Ok thanks for the help but the other side of my problem is with my ground it and one of my other actors dissapear soon as I click game mode the only thing I did to them was add animations. The only way to stop them from dissapearing ive found is to put them on the top half of my screen which screws me because im talkin about my soild ground.

PostPosted: Sun Apr 22, 2007 12:07 pm
by shady7twenty4
I think i fixd my problem. or at least found a way to work around it

PostPosted: Sun Apr 22, 2007 1:16 pm
by shady7twenty4
I had to use some of both of your responses to get it to work. Sgt. with yours something was wrong with my key down to jump, it did nothing but the rest was helpful. Soldier yours gave me a bounce effect when he came back down to the ground. I stil have one problem i can jump as high as long as i keep the up button down, but i only want him to b able to jump a certin heighth.

PostPosted: Sun Apr 22, 2007 1:30 pm
by Sgt. Sparky
shady7twenty4 wrote:I had to use some of both of your responses to get it to work. Sgt. with yours something was wrong with my key down to jump, it did nothing but the rest was helpful.[big space]problem i can jump as high as long as i keep the up button down, but i only want him to b able to jump a certin heighth.

did you do everything I told you to add?(without the other jumpin' script, just my jumping script only)remove the other jumping code you have now and try mine, I use it in all my games that jump.
but I usually do not make key down events,
I just make a code and put it in the draw actor event,
example:
Code: Select all
char*key=GetKeyState();
yvelocity += 1;
if(fly == 0) {
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0)
{
    gs = 0;
    if(jump == 1)x -= 5;;
    if(jump == 0)xvelocity -= 1;
    if(af == 1 && jump == 1 && key[KEY_DOWN] == 0) {
    af = 0;
    ChangeAnimation("Event Actor", "WL 1", FORWARD);
                                                   }
        if(af == 1 && jump == 1 && key[KEY_DOWN] == 1) {
    af = 0;
    ChangeAnimation("Event Actor", "CL 1", FORWARD);
                                                   }
    if(af == 1 && jump == 0) {
        af = 0;
        ChangeAnimation("Event Actor", "LJ 1", FORWARD);
                             }
}
if(key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 1)
{
    gs = 1;
    if(jump == 1)x += 5;
    if(jump == 0)xvelocity += 1;
    if(af == 1 && jump == 1 && key[KEY_DOWN] == 0) {
    af = 0;
    ChangeAnimation("Event Actor", "WR 1", FORWARD);
                                                   }
        if(af == 1 && jump == 1 && key[KEY_DOWN] == 1) {
    af = 0;
    ChangeAnimation("Event Actor", "CR 1", FORWARD);
                                                   }
    if(af == 1 && jump == 0) {
        af = 0;
        ChangeAnimation("Event Actor", "RJ 1", FORWARD);
                             }
}
if(key[KEY_UP] == 1 && jump == 1) {
    if(gs == 0)ChangeAnimation("Event Actor", "LJ 1", FORWARD);
    if(gs == 1)ChangeAnimation("Event Actor", "JR 1", FORWARD);
    yvelocity = - 15;
    jump = 0;
                                  }
if(xvelocity > 5 && jump == 0)xvelocity = 5;
if(xvelocity < -5 && jump == 0)xvelocity = -5;
             }
if(yvelocity > 2)jump = 0;

:D
there are alot of events in this,
here is what I have so far of this game I am workin' on xD
not much so far.
this game once I add more stuff is going to be like an Agent sort of game,
you have to do simple tasks in a complicated way.
xD
once I add stuff it is going to be stuff like getting bread off the top of the level,
I will add bomb dudes guys with guns, everything! :D