Author Topic: Sonic Physics  (Read 20242 times)

0 Members and 1 Guest are viewing this topic.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Sonic Physics
« on: November 05, 2010, 05:31:12 pm »
So a small revival of the sonic idea a couple days ago got me looking at the sonic thread on UTI, and the first thing i looked at were the ways they were implementing the physics.  I hate to say it, but i think they were going around it the wrong way.  And i don't say this because i claim my way is better, but because there is a site dedicated to the physics of the original sonic

http://info.sonicretro.org/Sonic_Physics_Guide

and it gives very explicit (and very different) algorithms to calculate the physics.  It covers all the quirks and features, right down to the very method it implements for things like sonic running on ceilings and such.  Note that writing an actual accurate physics engine is not what is needed for sonic, since there are numerous times in the game where you do things like run on the ceiling, or stay on the ground when you should be flying off.  

Keeping all of this new info in mind, i wrote a quick demo using the same concepts and algorithms from the original sonic.  The largest feature is the 5 mode directional physics.  The player can be in 1 of any 5 modes at a time:

1:Floor mode
2:Right wall mode
3:Left wall mode
4:Ceiling mode
5:Air mode

whenever the player is in one of the first 4 modes, he is stuck to that direction.  For example if the player is in Floor mode, the player can only move left and right, and then the engine moves the player up or down to make him level with the ground.  When the player starts going up a hill, it eventually changes to Right Wall mode.  Now gravity is basically acting to the right.  The player moves up and down, and the engine makes sure he sticks to the wall left to right.  This happens through all 360 degrees of possible walls.

Without the 5th mode, the player would always stick to the wall and never fall off, even if you were on the ceiling.  For this, whenever the player is in ceiling mode, if the velocity is lower than a certain value, the player enters Air Mode.  Where he is floating in mid air, and follows a trajectory until he hits a wall, where the player re enters one of the 4 modes.

So this is a basic tech demo just for fun, there is no scrolling, just a small map.  Its all tile based, there are 16 tiles, and each one of them has its own angle associated with it.  Use arrow keys to move and second to jump.  Oh and also note that this is not a project of any kind, i could never bring myself to start a project as large as sonic :P
« Last Edit: January 02, 2012, 11:59:46 pm by Builderboy »

ASHBAD_ALVIN

  • Guest
Re: Sonic Physics
« Reply #1 on: November 05, 2010, 05:47:25 pm »
ooh, interesting!  Those physics look amazing, but I'd hate to say you're right about sonic, it's a HUGE project for 1 person :P

Either way, UTI people would've been grateful for this, if their forum wasn't dead :P

I guess you really are the physics master :D
« Last Edit: November 05, 2010, 05:47:40 pm by ASHBAD_ALVIN »

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Sonic Physics
« Reply #2 on: November 05, 2010, 05:49:04 pm »
ooh, interesting!  Those physics look amazing, but I'd hate to say you're right about sonic, it's a HUGE project for 1 person :P

Either way, UTI people would've been grateful for this, if their forum wasn't dead :P

I guess you really are the physics master :D

Well considering Madskillz is around here he might still be grateful for this ;)

But that looks really cool :) I will mess around with this :D Looks really amusing to play with :P
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Sonic Physics
« Reply #3 on: November 05, 2010, 05:52:11 pm »
Heh thanks :) And the farthest i think i would take this is making it smoothscrolling, although that would be quite a challenge because i have yet to see a high frame rate tilemapper in Axe yet.  That and i would have to modify the engine a bit, since it uses a combination of tile detection *and* pixel Testing in order to do the physics.  I think a smoothscrolling engine with these physics would be plenty awesome ^^

Also note that the source is included, although horribly horrible optimized. I divide by 32 like a bazillion times per frame, and so that could be optimized for both size and speed.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Sonic Physics
« Reply #4 on: November 05, 2010, 05:53:51 pm »
Ah ok. That would be cool though if that happened :)

I found a bug, I think, but I have no idea what I did. I was messing around and then out of nowhere my guy just disappeared O.o I'll try to replicate it.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Sonic Physics
« Reply #5 on: November 05, 2010, 05:55:00 pm »
Ooh yeah thats right, there is a very small bug where the guy randomly disappears when you land on a slope :(

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Sonic Physics
« Reply #6 on: November 05, 2010, 05:55:01 pm »
I found a bug, I think, but I have no idea what I did. I was messing around and then out of nowhere my guy just disappeared O.o I'll try to replicate it.
I did it too. O.o

Great job Builderboy, that's an excellent demo. ;D

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Sonic Physics
« Reply #7 on: November 05, 2010, 05:57:19 pm »
Do you know why it only happens randomly?
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Sonic Physics
« Reply #8 on: November 05, 2010, 05:59:15 pm »
well not randomly, just hard to replicate :P And currently hard to fix.  It has to do with when you land, the engine putting you in the wrong mode for where you are.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Sonic Physics
« Reply #9 on: November 05, 2010, 06:01:56 pm »
Ah ok, gotcha. Well that sucks it's hard to fix. Is it just because since it's on a slope it has to decide what plane you're on and it has issues picking the right one because of that?
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: Sonic Physics
« Reply #10 on: November 05, 2010, 06:04:22 pm »
this is wonderful, builder!
as for smooth-scrolling: what i'm working on right now might work, but i'm not sure if it would be fast enough(especially for vertical scrolling)
still, this shouldn't be allowed to go to waste.

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Sonic Physics
« Reply #11 on: November 05, 2010, 06:05:12 pm »
That's really cool Buliderboy! Everything you said in your initial post makes perfect sense. It's a very cool little demo. =)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Sonic Physics
« Reply #12 on: November 05, 2010, 06:07:57 pm »
exactly, if you are on a slope it has to decide if you are closer to one axis than the other, and due to another optimization that i made, i am forced to use pixelTesting, which fails in certain places.  I *should* be using the engle of the tile you collide with, but i did an optimization where i use only 1 8x8 filled box for all 4 angles flat tiles.  The floor, walls, and ceiling are all the same tile, but they all have different angles.  I change the angle value of that specific tile when i switch modes, but that means that when you travel through the air, the angle of the flat tile cannot be predicted or relied on.

The simple fix would be to add 3 mode identical looking tiles with different angles, but i would have to rewrite the mapping engine a bit since it would go over 16 tiles and i just didn't feel like it :P

And shmibs, what type of scrolling engine do you have?

Art_of_camelot thanks :) I really hope that if sonic is ever picked up again that the physics engine is given an upgrade, as in the last demo i saw, slopes weren't handled correctly.

Offline Madskillz

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 488
  • Rating: +32/-2
    • View Profile
Re: Sonic Physics
« Reply #13 on: November 05, 2010, 06:10:04 pm »
Wow looks great builderboy. I'll have to see what Digi used for his physics, but yours definitely looks smooth. I assume it's made with Axe? At least the idea could be ported over to ASM.

Somebody should definitely use this, if not for a Sonic game, perhaps a sidescrolling platformer type of game.

Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: Sonic Physics
« Reply #14 on: November 05, 2010, 06:12:28 pm »
right now it draws two rows of sprites across the entire screen per shift, so i'm certain it could be optimized further(EDIT: especially if it didn't need to handle 100's of different tile types, in which case different shifts could be hardcoded like penguin mentioned doing in his new version of the impossible game), but it allows the screen to shift 1-8 pixels in any direction without any difference in speed between different shift distances.
« Last Edit: November 05, 2010, 06:15:38 pm by shmibs »