Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / jumping question

Author
Message
pjsmith67
8
Years of Service
User Offline
Joined: 2nd Feb 2016
Location: Nebraska, USA
Posted: 12th Feb 2018 05:02
Ok, I'm tinkering around with doing a platform game. I have the sprite moving and jumping just fine with physics. However, I want the sprite to jump through the platform above it. Right now it just hits it and bounces back down. The platform sprites have physics turned on to static.

Basically, the first time it jumped, I want it to just up a bit into the next platform, and then a double jump makes it go all the way up and land on it. I have the double jump working but can't do it when a platform is right above it because physics is on and the sprite just bumps his head.

How would I go about doing this? just need a pointer in the right direction. Thanks!

Phil
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 12th Feb 2018 05:08 Edited at: 12th Feb 2018 05:15
If you are using physics with the platforms you would need to switch off the physics to the above platform prior to jumping and then back on again before you land

Not sure what game you a trying but heres a thought
If the platforms physics are only for the player when you set up the platforms only set the physics on the bottom starting platforms after you have reached your max jump height
then have a routine that then sets the physics of the next lowest platform to on and the physics of all other platforms to off.
fubar
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 12th Feb 2018 09:46
You could just have the platform and character on different sprite groups while the character is below platform. Once the character is above the platform, set them to the same group. If the bottom of the character dips below the the platform, then set them back to different groups.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 12th Feb 2018 10:16
Good idea IronManhood
fubar
pjsmith67
8
Years of Service
User Offline
Joined: 2nd Feb 2016
Location: Nebraska, USA
Posted: 12th Feb 2018 15:18
Yeah, I thought of the turning physics on and off but didn't think of the changing sprite groups. Hmmm... both are good ideas. I was just wondering if there was something I could set in the physics system to do it. Either one of those ideas should work, though.

Not even sure what kind of platform game I'm going to produce yet. Right now I'm just tinkering and learning how to do the mechanics for one.

Thanks!

Phil
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 12th Feb 2018 15:29 Edited at: 12th Feb 2018 16:39
Quote: " I was just wondering if there was something I could set in the physics system to do it"

What you are asking for there is: Can you set the physics system to ignore collisions in one direction but accept them in another. And the answer to that is no.
Personally, I'd go with the sprite groups option but turning off and on again works too.

It can't be done in Box2D either but there is a good discussion on the various ways to tackle it here.
hoyoyo80
8
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 12th Feb 2018 22:46
Tq all..ive been wondering the same thing but since i have no platformer project so i dont wanr to think of it.

GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 12th Feb 2018 22:56 Edited at: 12th Feb 2018 22:58
Granted I am not familiar with using physics in 2D games I just check for collisions against tile map cells.

BUT... the same general idea applies. Can't you just disable collision on the player object when the velocity has it moving up. And then enable collision on the player object again as soon as its velicity has it falling? That seems like the logical simple way to do it instead of trying to disable collisions on platforms within a certain proximity.

Or is the problem that you have no way of knowing what the player velocity is when using physics other than storing its LastPosition in a variable at end of each frame? This kind of thing is reason I dislike using these canned systems. I always hit something I want to do and have to work around the system. In this case it might not be bad though just save the position of player y yourself and compare. When you detect it is falling enable collisions. Of course disable collison on it as soon it jumps.

BUT would be much better if you could call a function to just get what its current velocity is and use that. You would still want to use a variable or whatever and check that if CollisionEnabled don't enable it again and vice-versa.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 13th Feb 2018 07:54 Edited at: 13th Feb 2018 07:56
Quote: "Can't you just disable collision on the player object when the velocity has it moving up. And then enable collision on the player object again as soon as its velicity has it falling?"

That would work perfectly if (and only if) all platforms were perfectly horizontal. As soon as you introduce a slight angle your system falls apart.
With that system in place, if your player tried walking down an slope he would pass straight through it as though it wasn't there.
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 13th Feb 2018 09:42
Quote: "That would work perfectly if (and only if) all platforms were perfectly horizontal. As soon as you introduce a slight angle your system falls apart.
With that system in place, if your player tried walking down an slope he would pass straight through it as though it wasn't there."

You mean up a slope but still not strictly true, you would simply disable the player collision when jumping and moving up, as it will require a jump button it would be simple enough to check... To walk up a slope you wouldn't be jumping and even if you did jump you will be above it so you would be fine, though switching off the player collision may make him immune to damage while jumping so you would need to account for that in any such code.

The other issue I see with the request is more that it would technically be possible to get stuck inside a platform so you would need to check for that too.
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 15th Feb 2018 17:53 Edited at: 15th Feb 2018 17:55
As said above, checking player velocity and changing collidebits works. I figured I would share some code I made for an old attempt at a platformer that worked well for this.

This code obviously won't compile unless the player type is set up correctly 'n that



Just noticed that the platformCount integer isn't changed in the loop creating platforms in this code, which you would want
My hovercraft is full of eels

Login to post a reply

Server time is: 2024-11-24 00:59:21
Your offset time is: 2024-11-24 00:59:21