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 / Character Sticking - Platformer [Tier 1]

Author
Message
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 14th Sep 2012 14:56
Hello, I have seen several WIP's for platformers and thought it would be a decent challenge to try myself.

I'm using Box2D and I've got the basics working well, I can move my character around, jump, load levels etc etc, but for the life of me I can't stop the character 'sticking' to the walls/platforms when I jump into them. I have seen that the WIP's have achieved this nicely so was wondering if someone could give me some pointers! Many thanks!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Sep 2012 16:33
I would do a raycast from the centre of the character to the left and right (slightly larger than the edge of your character shape). If you get a hit don't let the player move in that direction (or apply any force in that direction depending how you are moving your character).


this.mess = abs(sin(times#))
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 14th Sep 2012 19:07
If your level uses tiles and the player uses an box collision shape so will it stick to the tile edges.

Simply use an circle shape for the player instead.

Android 2.3 Gingerbread , ZTE Skate , 480x800 , 800 mhz cpu , Samsung Galaxy Y , 240x320 , 832 mhz cpu
Android 4.0 Sandwich , Dmtech 3g 9738B , 1024x768 , 9.7 inches , cortex A8 1.2 cpu , 1 gb ram.
MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 14th Sep 2012 22:39
I think Funnell7 means when a character is falling, and it is adjacent to a platform and moves towards it, it seems trying to grasp the platform and reduce its descending speed.
I left it in my platform (MrOttoBeat) and it give a curious effect that may be pleasant or not, depends on your taste.
My platform is not tile-based, I place many static objects in the world. I did not try the raycast, I wonder if we have to mark each sprite with category or group in order to filter out all objects that are not "platforms".
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 15th Sep 2012 10:58
I and others in the WIP board does not use the built in physics. It is not really made for platformers. I use the built in collection detection and check for what AppGameKit calls contacts and use that to reposition my sprites. The physics also makes it hard to have perfect control over the feel of your game. In Rush to Adventure I use exact player control (similar to games like Megaman). The player have full control and as soon as the button is released the hero stops. There are other platform controls that also are not suited to the built in physics. Had I known how badly suited Box2D is for my game I would have saved me hours and hours by coding my own from scratch.

But Cliff is using the physics for his game and I am impressed by his accomplishments with it. It is not the feel I am looking for in my game, but platform games have different feels.


Demo 2 is out! Click the image for more.
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 15th Sep 2012 12:22
@Digital Awakening, I would love to be able to build my own physics, but unforuntately that is too advanced for me at this stage...

@Cliff, I was hoping it would be something as simple as that but that doesn't work for me.

Here is some simple code to give you an idea of what I'm struggling with. No media required. Use the arrow keys to move left/right and space to jump. If you jump into the platform in the middle and keep holding right, the character sticks to the platform. This happens for the left and right wall also. I think I need to do something as mentionen by Baxslash? Any help would be much appreciated...

Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 15th Sep 2012 13:14
Here is my movement code in my platformer engine

Bare in mind that it is rough stuff!



Android 2.3 Gingerbread , ZTE Skate , 480x800 , 800 mhz cpu , Samsung Galaxy Y , 240x320 , 832 mhz cpu
Android 4.0 Sandwich , Dmtech 3g 9738B , 1024x768 , 9.7 inches , cortex A8 1.2 cpu , 1 gb ram.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Sep 2012 13:49
I use physics for just about everything, including platform games. The built in physics system (Box2D) is ideal for far more than you might think. It can save the need for manually working out jump arcs, sliding collision and a range of other problems.

People tend to not use it because it sounds complicated but actually it simplifies a range of tasks.


this.mess = abs(sin(times#))
MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 15th Sep 2012 15:25
@Digital Awakening: Box2D is good for platformer, and for all other things. I used it the pinball game, the platform game and the space game and, apart my graphics that could not be liked by everyone , they work very well with physics. Of couse, physics is the basics.
On the pinball, you have to build special bouncing and launching effects on top of Box2D.
For platform, you have to consider a lot of cases: jumping, walking, hanging on ropes, being on moving platforms, falling, etc.
This leads to a lot of states that could be modeled with a state-machine. Also speed affects the behaviour of your character.
I use a state-machine like control that takes as input the states and the speed of the character, plus other controls related to the platform below it. In fact, when the character is on a moving block, it does not move together with the block, as friction does not exist. I tried all commands about friction, but no one works.
So it is more complicated, but far more realistic to use physics. Not to use physics means develop an old-style platform (like SuperMario Bros), with artificial movements and simulated jumping that does not convince very much. It is my poor opinion, of course, I am not a TGC developer.
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 15th Sep 2012 16:30
baxslash:
I spent hours trying to get the physics to work in my game and ended up with a far less than perfect result. Then I made my own and everything works exactly the way I want it to. I don't have time but if I did I would code my own collision detection as well and be rid of the very minor glitches I have now as well as the limitations of the system.


Demo 2 is out! Click the image for more.
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 16th Sep 2012 13:05
So... After a couple hours of trial and error, I have finially got it working perfectly!! I did as suggested by Baxslash and created a raycast slightly larger than my character. I then check for collisions with platforms etc before adding directional velocity!

Thanks you all for the comments and suggestions!! Gotta love AppGameKit!

Login to post a reply

Server time is: 2024-05-04 19:42:50
Your offset time is: 2024-05-04 19:42:50