Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411807 Posts in 69416 Topics- by 58462 Members - Latest Member: Moko1910

May 29, 2024, 01:58:50 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Noober Game Maker issue involving jumping.
Pages: [1]
Print
Author Topic: Noober Game Maker issue involving jumping.  (Read 1822 times)
gunmaggot
Guest
« on: January 06, 2010, 07:44:44 PM »

I've started reverse-engineering the GM platformer tutorial to see if I can get it to do what I want for my game and it didn't take long for me to fall on my face, so I was hoping somebody here could babysit me a bit.

I changed the jump to an infinite air jump - sort of like flapping in Joust.  That was easy.  But things got tricky when I tried to make the player character hover in place when the jump button is held while in mid-air.  Basically, what I want is for the player to be able to keep tapping jump to keep jumping in the air, but to stop when jump is held down so the player object can hover around in eight directions like your standard videogame spaceship, with gravity returning once again when the button is released.
I have tried a bunch of different things, like switching the instance of the player object to a hovering object, but I don't really know what I'm doing and weeeeeiiiiird things happen - the gravity is held over from one object to the other or something and the character will either rocket upwards indefinitely or fall instantly, or maybe it teleports to some odd location in the room, depending on the latest thing I've tweaked.

Basically, I'm lost and I need some help - preferentially, using GM's drag and drop visual interface.  I am not even remotely ready for even simple coding, and I doubt I ever will be.

Thanks a lot.
« Last Edit: January 06, 2010, 08:16:08 PM by gunmaggot » Logged
gunmaggot
Guest
« Reply #1 on: January 07, 2010, 12:38:20 AM »

Never mind, I'm a spaz - all I really needed was patience and concentration.  I haven't quite solved the problem yet but I'm totally on the right track.  Thanks to everybody who clicked on my thread!
Logged
Desert Dog
Level 4
****



View Profile
« Reply #2 on: January 07, 2010, 12:58:13 AM »

Glad you got it sorted then. Smiley

I spent the last 10 minutes, whipping up this example (mainly because I thought the gameplay mechanics you described sounded interesting) and because I don't like wasting it, I'll share it with ya.



I'm sorry, it IS in code, but I heavily commented it. Even so, I'm not the best coder, so it's actually a bit messy.

I had problems with the gravity, for some reason, it was spazzing onto 1, when trying to hover. so, I'm afraid that in this example, when you hover, you still slowly drift down. Should be easy enough to fix, though, I suspect it's just a gm6 bug. (never had a problem like this with gm7)



Logged

gunmaggot
Guest
« Reply #3 on: January 07, 2010, 01:44:16 AM »

Oh wow, that's completely awesome - thankyou so much.
It's funny: my spacebar and arrow keys conflict so the aerial movement was off for me in your example - that forced me to suck it up and actually dip into the code and tweak it.  It sounds kind of silly, but that was a real useful exercise for me.  I don't think I'll be doing any coding with GML any time soon, but it was great to know that maybe it's not completely beyond my understanding.  I really appreciate the annotations, they were super helpful.
The way gravity still stays with the hovering object is strange, but I'm not sure it's a problem - when I was envisioning how the movement worked in my head I never made up my mind whether I wanted it to stay put or fall a little bit and require a bit of input upkeep.
Logged
Desert Dog
Level 4
****



View Profile
« Reply #4 on: January 07, 2010, 03:30:16 AM »

Oh wow, that's completely awesome - thankyou so much.
It's funny: my spacebar and arrow keys conflict so the aerial movement was off for me in your example - that forced me to suck it up and actually dip into the code and tweak it.  It sounds kind of silly, but that was a real useful exercise for me.  I don't think I'll be doing any coding with GML any time soon, but it was great to know that maybe it's not completely beyond my understanding.  I really appreciate the annotations, they were super helpful.
The way gravity still stays with the hovering object is strange, but I'm not sure it's a problem - when I was envisioning how the movement worked in my head I never made up my mind whether I wanted it to stay put or fall a little bit and require a bit of input upkeep.

Definitely get into using the code. It takes a while to nail (regularly using it, maybe a month?) but once you do it, it's 100% easier to write and maintain your games with. It's also a lot easier for reading, etc.

To be honest, I'm not even sure why the gravity is acting that way.. if you want to do a quick test, pop this into a code box in the obj_ball's draw event:
Code:
draw_sprite(sprite_index,image_index,x,y); // draw our sprite...

draw_text(x,y-16,string(gravity)); //draw the value of gravity.

You'll notice that when it 'hovers' gravity flickers between 0 and 1.
I bet it's something silly I'm doing. :p

(comes back after a few minutes testing)

Yes, yes, I'm an idiot. Sorry, here is a snippet from the Step even which I edited.
Code:
if place_free(x,y+1) // if nothing solid is beneath us...
{
    gravity_direction=270; //270 is down.
    gravity=1; // a nice, weak gravity.
   
    //okay, this next bit is a little higgly. BUT it's to get the code working 100%
    //all it does, is check if our vspeed is positive (i.e. we are falling)
    // and if we are meant be be hovering. Simple!
    if hover=true // we aren't meant to fall.. we are meant to hover.
    {
        if vspeed>=0 // we are falling!
        {
            vspeed=0; //then don't fall! Dumkoff!
            gravity=0;
        }
    }
}

Notice the difference? Yes, the if vspeed>=0. I didn't put the '=' sign in.

Just pop that '=' sign in, over there (it means, if vspeed is larger than, or equal to 0 )
and then your good to go!

I really shouldn't be coding past 12 :p G'nite mate, hope this helps ya.  Coffee
Logged

gunmaggot
Guest
« Reply #5 on: January 07, 2010, 05:38:10 PM »

Thanks, I added that to the code and it's perfect now. 
I did some more fumbling, tweaking numbers and stuff to get it how I envisioned it and I decided that you're right - I need to learn GML if I'm ever going get this game how I want it.  Luckily, I took some time off work for the holidays so I can do this properly.

Back when I was lurking and before I had even used the drag & drop functions of GM I tried out Derek's GM tutorial, but going in cold without having really used the basic interface, I just confused myself, and that really put me off GML altogether - but looking at how you did what I was trying to do I realised that if I put the effort in this is something I can definitely do.  Thankyou so, so much!
Logged
Destral
Level 10
*****


Climbing that mountain...


View Profile WWW
« Reply #6 on: April 04, 2010, 12:18:05 AM »

Glad you got it sorted then. Smiley

I spent the last 10 minutes, whipping up this example (mainly because I thought the gameplay mechanics you described sounded interesting) and because I don't like wasting it, I'll share it with ya.



I'm sorry, it IS in code, but I heavily commented it. Even so, I'm not the best coder, so it's actually a bit messy.

I had problems with the gravity, for some reason, it was spazzing onto 1, when trying to hover. so, I'm afraid that in this example, when you hover, you still slowly drift down. Should be easy enough to fix, though, I suspect it's just a gm6 bug. (never had a problem like this with gm7)

I've been trying to figure out on my own how to make the player jump for a side project I'm working on, but after failing miserably I decided to look on here to see if anyone had a solution. After looking at your example, I think I understand how it works, so I'm going to give it another go based on what you've done. Just thought I'd post a quick 'Thankyou!'.  Beer!
Logged

Currently working on: Sword Surfer
Desert Dog
Level 4
****



View Profile
« Reply #7 on: April 04, 2010, 02:27:45 PM »

Your welcome! It's just as well I didn't take the file down then.  Wink
Logged

Falmil
Level 6
*


View Profile
« Reply #8 on: April 04, 2010, 04:35:57 PM »

I would probably just implement position, velocity and acceleration and have the "jump" button create enough upward acceleration to cancel the gravity while having a drag constant lower horizontal and vertical speed to 0. Then the arrows could just turn on the x/y speed/acceleration. Of course, that's probably more complex. I guess I just like things more technical and rule based.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic