Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: Builderboy on November 05, 2010, 05:31:12 pm

Title: Sonic Physics
Post by: Builderboy 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
Title: Re: Sonic Physics
Post by: ASHBAD_ALVIN 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
Title: Re: Sonic Physics
Post by: meishe91 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
Title: Re: Sonic Physics
Post by: Builderboy 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.
Title: Re: Sonic Physics
Post by: meishe91 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.
Title: Re: Sonic Physics
Post by: Builderboy 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 :(
Title: Re: Sonic Physics
Post by: ztrumpet 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
Title: Re: Sonic Physics
Post by: meishe91 on November 05, 2010, 05:57:19 pm
Do you know why it only happens randomly?
Title: Re: Sonic Physics
Post by: Builderboy 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.
Title: Re: Sonic Physics
Post by: meishe91 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?
Title: Re: Sonic Physics
Post by: shmibs 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.
Title: Re: Sonic Physics
Post by: TIfanx1999 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. =)
Title: Re: Sonic Physics
Post by: Builderboy 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.
Title: Re: Sonic Physics
Post by: Madskillz 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.
Title: Re: Sonic Physics
Post by: shmibs 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.
Title: Re: Sonic Physics
Post by: JustCause on November 05, 2010, 06:12:47 pm
Wow! This looks quite nice. I may steal the 5-mode concept from you, it seems like it's working great and would lead to a robust engine.
Title: Re: Sonic Physics
Post by: DJ Omnimaga on November 05, 2010, 06:18:07 pm
Wow that is too great! I am amazed at how you managed to get the physics so close (well... faster but still...). On top of that, it was at 6 MHz! I tried it at 15 and it was ultra-fast.

Do you think with smooth scrolling it could be fast enough?
Title: Re: Sonic Physics
Post by: Builderboy on November 05, 2010, 06:21:09 pm
Its not my concept so go ahead :)

And shmibs that sounds like what i have done, we will have to compare engines :)

And thanks DJ :) I hope smoothscolling can work, as that is kind of what i am aiming with this whole tech demo.  I just need a fast enough engine and it should be good.  It is surprising how little power it takes to run this physics engine.  Even in Full i didn't get the speed increase i expected because the framerate was getting to the max the calc could handle O.O and i haven't even optimized it!  I guess the guys as Sega knew what they were doing :)
Title: Re: Sonic Physics
Post by: meishe91 on November 05, 2010, 06:29:38 pm
Its not my concept so go ahead :)

And shmibs that sounds like what i have done, we will have to compare engines :)

And thanks DJ :) I hope smoothscolling can work, as that is kind of what i am aiming with this whole tech demo.  I just need a fast enough engine and it should be good.  It is surprising how little power it takes to run this physics engine.  Even in Full i didn't get the speed increase i expected because the framerate was getting to the max the calc could handle O.O and i haven't even optimized it!  I guess the guys as Sega knew what they were doing :)

Well not every technology company is like TI ;)
Title: Re: Sonic Physics
Post by: FinaleTI on November 05, 2010, 06:49:25 pm
Its not my concept so go ahead :)

And shmibs that sounds like what i have done, we will have to compare engines :)

And thanks DJ :) I hope smoothscolling can work, as that is kind of what i am aiming with this whole tech demo.  I just need a fast enough engine and it should be good.  It is surprising how little power it takes to run this physics engine.  Even in Full i didn't get the speed increase i expected because the framerate was getting to the max the calc could handle O.O and i haven't even optimized it!  I guess the guys as Sega knew what they were doing :)
Well, they did. At least for the classic Sonic games. The new ones are really not that good, unfortunately.
Title: Re: Sonic Physics
Post by: Builderboy on November 05, 2010, 06:51:35 pm
Well i was talking more on the code efficiency part, they came up with a method that is super duper fast ^^
Title: Re: Sonic Physics
Post by: DJ Omnimaga on November 05, 2010, 06:52:50 pm
Its not my concept so go ahead :)

And shmibs that sounds like what i have done, we will have to compare engines :)

And thanks DJ :) I hope smoothscolling can work, as that is kind of what i am aiming with this whole tech demo.  I just need a fast enough engine and it should be good.  It is surprising how little power it takes to run this physics engine.  Even in Full i didn't get the speed increase i expected because the framerate was getting to the max the calc could handle O.O and i haven't even optimized it!  I guess the guys as Sega knew what they were doing :)
Well, they did. At least for the classic Sonic games. The new ones are really not that good, unfortunately.
True, especially remakes of the old ones as well as ports. The worst is Sonic The Hedgehog Genesis for the GBA. It's filled with physic glitches.
Title: Re: Sonic Physics
Post by: Builderboy on November 05, 2010, 06:53:42 pm
Yuk, although the site i linked to does mention a glitch in the original sonic where if you fall from too high you can pass through objects D:
Title: Re: Sonic Physics
Post by: ztrumpet on November 05, 2010, 06:55:56 pm
Yuk, although the site i linked to does mention a glitch in the original sonic where if you fall from too high you can pass through objects D:
Terminal Velocity anyone? :P
Title: Re: Sonic Physics
Post by: Builderboy on November 05, 2010, 07:01:49 pm
heh yeah they fixed it in all the later versions i believe, there might not have been even that many places in the original sonic where you could even build up enough velocity o.O
Title: Re: Sonic Physics
Post by: DJ Omnimaga on November 05, 2010, 09:35:12 pm
Haha I think that happened in Supersonic Ball before I slowed down falling XD. When moving down at a 4 pixel interval in a direction AND vertically, then landed in the very corner of two tiles, you went through it.
Title: Re: Sonic Physics
Post by: fb39ca4 on November 05, 2010, 09:39:16 pm
Reminds me of a flash game I played called Flipside (http://nitrome.com/games/flipside), where you can drive up walls in your car, if you have enough speed. A calc version of flipside could be done with physics like this, too.
Title: Re: Sonic Physics
Post by: DJ Omnimaga on November 05, 2010, 10:36:47 pm
Wow, that flash game takes A LOOOOOOOONG while to load O.O. It reminded me when we had dial-up at school, shared between 64 computers O.O
Title: Re: Sonic Physics
Post by: MRide on November 05, 2010, 10:51:27 pm
And once again, the master of physics showcases his talent. :P
But seriously, nice job on this, Builderboy!
Title: Re: Sonic Physics
Post by: meishe91 on November 05, 2010, 11:02:26 pm
And once again, the master of physics showcases his talent. :P
But seriously, nice job on this, Builderboy!

Not that it's inaccurate ;)
Title: Re: Sonic Physics
Post by: MRide on November 05, 2010, 11:03:44 pm
No, but it sounded a little...formal, so maybe it should be "not-quite-so-seriously" :P

EDIT: 500th post!!
Title: Re: Sonic Physics
Post by: willrandship on November 05, 2010, 11:07:10 pm
how illegal would it be to disassemble the original SEGA rom and use their method? :P
Title: Re: Sonic Physics
Post by: Iambian on November 05, 2010, 11:27:23 pm
That looks pretty amazing. If I wasn't bogged down by the whole E:SoR and CaDan thing, I would so totally go for this sort of project.

Then again... maybe it could be re-visited...
It would *have* to be in ASM, tho...
Title: Re: Sonic Physics
Post by: meishe91 on November 05, 2010, 11:33:34 pm
how illegal would it be to disassemble the original SEGA rom and use their method? :P

Well since that site Builder linked to apparently shows the exact method they used I don't think it'd be that bad :P ;)
Title: Re: Sonic Physics
Post by: DJ Omnimaga on November 06, 2010, 04:50:00 pm
I wouldn't be surprised if Sonic was possible in Axe, but it would probably require 15 MHz mode or a huge drop in framerate (rendering every 3 or 4 frames, maybe)
Title: Re: Sonic Physics
Post by: meishe91 on November 06, 2010, 05:07:47 pm
Well if you didn't have smooth-scrolling I think it would be very possible. It'd be less Sonic like but still Sonic nonetheless ;)
Title: Re: Sonic Physics
Post by: DJ Omnimaga on November 07, 2010, 03:54:45 am
Well even with "smooth" scrolling it might be possible, but not super smooth. It would kinda be like when you play a game on a computer which got specs that are too low to run the game at decent speed.

An example would be how I did the faster speed in Axe Tunnel, but worse. At 5x speed, the thing I do is simply refresh the screen every 5 frame.
Title: Re: Sonic Physics
Post by: Builderboy on November 07, 2010, 02:19:57 pm
I think that with a smoothscolling axiom, Sonic would be possible in 6Mgz in Axe :)
Title: Re: Sonic Physics
Post by: DJ Omnimaga on November 07, 2010, 03:26:05 pm
That could work, too. I hope Quigibo re-enables Axioms in future versions. Btw it's MHz :P
Title: Re: Sonic Physics
Post by: Builderboy on November 07, 2010, 03:29:09 pm
Oh thanks lol XD either way, possible or not, its a huge gigantic project
Title: Re: Sonic Physics
Post by: Madskillz on November 07, 2010, 04:08:40 pm
Gotta remember though that there is a lot going on. That sense of speed has to be there. There are other things going on in Sonic as well. The ring loss when you hit a spike or run into an enemy. You could make it that if sonic gets hit he doesnt lose any rings or like one I suppose. But like I said if the speed isnt there, you're just making a platformer with a hedgehog.
Title: Re: Sonic Physics
Post by: DJ Omnimaga on November 07, 2010, 05:09:41 pm
Oh right, the ring loss animation must be hectic. I wonder if we could simply do like the Game Gear version?
Title: Re: Sonic Physics
Post by: Madskillz on November 07, 2010, 06:42:29 pm
Yeah that might be possible, we went the similar route I think.
Title: Re: Sonic Physics
Post by: Builderboy on November 07, 2010, 06:44:31 pm
What was the game gear version?
Title: Re: Sonic Physics
Post by: DJ Omnimaga on November 07, 2010, 08:25:31 pm


It's pretty much a port of the Sega Master System version

Title: Re: Sonic Physics
Post by: willrandship on November 07, 2010, 08:32:02 pm
The original had you lose 20 rings, that's a lot of new objects. you could reduce the dropped rings to 10, like some later games do, and reduce the strain
Title: Re: Sonic Physics
Post by: DJ Omnimaga on November 07, 2010, 08:50:30 pm
In the SMS version, you don't see any link loss animation it seems, maybe you could just have like 4 rings being lost even if you lose 10?
Title: Re: Sonic Physics
Post by: Madskillz on November 07, 2010, 09:07:07 pm
I think it was 4 no matter how many you had...I think digi had Sonic dropping the actual number of rings you had. As a test he had 100 dropping and bouncing around it was pretty crazy. I think we decided on 4 or 5...I dont think we went with 10 but of course I know we talked about it at one time.

After seeing that speed of Runer's tilemapper and Builderboys physics...I definitely think an Axe version of Sonic can be done.  However I know of a few things that we had planned for the ASM Sonic and a few ideas that I know I would like to see, that just wouldnt be possible with Axe. Right now at least.

It is a huge project, but I think there are a ton of talented people that are extremely talented with Axe that could definitely pull off a version.
Title: Re: Sonic Physics
Post by: Builderboy on November 07, 2010, 09:16:25 pm
Well i for one am definitely not planning to make sonic (kudos to anybody who wants to pick it up, feel free to use my physics), i just want to be able to move around a smoothscrolling map ^^

Also Madskills, how far did the physics for the sonic project get?  I'm curious ;D
Title: Re: Sonic Physics
Post by: DJ Omnimaga on November 07, 2010, 11:49:55 pm
I think it was 4 no matter how many you had...I think digi had Sonic dropping the actual number of rings you had. As a test he had 100 dropping and bouncing around it was pretty crazy. I think we decided on 4 or 5...I dont think we went with 10 but of course I know we talked about it at one time.

After seeing that speed of Runer's tilemapper and Builderboys physics...I definitely think an Axe version of Sonic can be done.  However I know of a few things that we had planned for the ASM Sonic and a few ideas that I know I would like to see, that just wouldnt be possible with Axe. Right now at least.

It is a huge project, but I think there are a ton of talented people that are extremely talented with Axe that could definitely pull off a version.
Also, since this is a small 96x64 resolution, I don't think having an animation where 10 rings drops instead of 30 would make much of a difference, though, since the screen would either get cluttered or most rings would go outside.
Title: Re: Sonic Physics
Post by: Madskillz on November 08, 2010, 03:54:10 pm
I had sonic rolling off of ramps and slopes of various degrees. But that was working off of Digi's older 82 assembly code. In his later versions I'm pretty sure he had sonic going around loops. I remember we ran into an issue with the loops though. Early on the degree of the loop's starting position had to be modified. But I think we had that all worked out. Each of the coins had their own physics too. They would bounce around the screen. They were their own individual objects. I think he used some of that in Robot War 2. You can see some of the objects that the main character has bounce around when he drops them from his item list.

But your physics look really good. With those actual values from the site, we could craft the physics to be identical to the original. Which I know ours were not. I have been getting back into assemble here off and on during the wee hours of the night. I havent worked on Sonic again yet, but I am working on some stuff.
Title: Re: Sonic Physics
Post by: DJ Omnimaga on November 08, 2010, 03:58:10 pm
Yeah the loops looks like they would be hard to implement, especially jumping physics. For sure, Sonic's physics are much more complex than Mario.
Title: Re: Sonic Physics
Post by: Builderboy on November 30, 2011, 07:54:52 pm
Rawr!  I recently thought this would be really awesome if I implemented smoothscrolling!  So I implemented it!  Yayyy! I did run into some issues because my old code was kind of buggy (and there are still some very prominent bugs in this demo) but I managed to get it into a workable state nonetheless!  I used Runer's old shifting smoothscroller, and it ended up working very nicely!  To play you will need Program Axe and the appvar S in RAM, then run the Axe program, use the arrow keys and 2nd to move around and jump!

During the development, I became so frustrated with my old code that I switched to using Chainfire physics, which worked perfectly!  The downside was that you no longer got the same feeling you got when using the sonic physics.  So I switched back to sinic physics to keep the cool fun feeling while, and tolerated the occasional collision bug ^^
Title: Re: Sonic Physics
Post by: ztrumpet on November 30, 2011, 08:00:42 pm
That looks amazing.  It looks like you could make a game out of it now; excellent job, Builder.

What happens if a bug is triggered?
Title: Re: Sonic Physics
Post by: Builderboy on November 30, 2011, 08:03:07 pm
Mostly the ball just gets stuck or zooms in a weird direction, usually does not crash the game, but it can be a bit annoying.  As for making this a game, I'm done dealing with this old buggy code, if someone wan'ts to use it, they can go ahead :P
Title: Re: Sonic Physics
Post by: annoyingcalc on November 30, 2011, 08:25:37 pm
Nice! That is incredible
Title: Re: Sonic Physics
Post by: LincolnB on November 30, 2011, 10:18:24 pm
Awesome! Looks sweet.
Title: Re: Sonic Physics
Post by: aeTIos on December 01, 2011, 03:02:50 am
This looks great.
Title: Re: Sonic Physics
Post by: Hayleia on December 01, 2011, 12:33:01 pm
Please, someone. Please tell me that this game will be done !!!!
Title: Re: Sonic Physics
Post by: aeTIos on December 01, 2011, 12:36:35 pm
I lost it.
Title: Re: Sonic Physics
Post by: Eiyeron on December 01, 2011, 03:32:47 pm
W-W-WANNA THIS ON MY CALC!
Fuu! Why don"t I have any Ti calc?

Do you think port will be doable?
Title: Re: Sonic Physics
Post by: DJ Omnimaga on December 01, 2011, 06:54:42 pm
This is awesome builder and runs really smooth. I really like the camera too.

@Eiyeron only if somebody knows both Axe Parser and C I guess. Else this might require team work to help each others dechipering the code.
Title: Re: Sonic Physics
Post by: Eiyeron on December 02, 2011, 02:28:44 pm
Yup! Axe is for me a "byte" harder to understand.
Title: Re: Sonic Physics
Post by: C0deH4cker on December 03, 2011, 04:19:14 pm
Mostly the ball just gets stuck or zooms in a weird direction, usually does not crash the game, but it can be a bit annoying.  As for making this a game, I'm done dealing with this old buggy code, if someone wan'ts to use it, they can go ahead :P

Stupid question: where's the src?
Title: Re: Sonic Physics
Post by: Keoni29 on December 04, 2011, 03:40:24 am
Looks liek the real thing (except for the graphics)
Title: Re: Sonic Physics
Post by: Builderboy on December 04, 2011, 03:52:11 am
I'm pleased :) I found a website that explained the methods behind the original sonic physics, and I tried to port them as best I could, so I'm glad it looks so similar ^^
Title: Re: Sonic Physics
Post by: C0deH4cker on December 07, 2011, 01:40:39 pm
Stupid question: where's the src?

I know that the first post has the src, but that's the old version, right?
Title: Re: Sonic Physics
Post by: Builderboy on January 03, 2012, 12:00:26 am
For some reason I never released the source before, so now it has been released and is in the first post :D
Title: Re: Sonic Physics
Post by: C0deH4cker on January 06, 2012, 05:53:48 pm
Thanks!
Title: Re: Sonic Physics
Post by: kindermoumoute on January 06, 2012, 07:38:00 pm
Just awesome ! A lot of bug, but while it's on emulator.
Thank to share source. :)
Title: Re: Sonic Physics
Post by: Builderboy on January 06, 2012, 08:01:49 pm
Yeah I mentioned before the physics is realllly buggy in general
Title: Re: Sonic Physics
Post by: saintrunner on January 06, 2012, 08:11:31 pm
This makes me think a calc 'line rider' is possible! If you haven't hear of line rider check out www.linerider.com to play it :)
This is so cool!
Title: Re: Sonic Physics
Post by: annoyingcalc on January 06, 2012, 09:44:34 pm
there is one ill post a link in a sec

edit done http://www.ticalc.org/archives/files/fileinfo/394/39489.html
Title: Re: Sonic Physics
Post by: saintrunner on January 06, 2012, 09:51:22 pm
That looks cool, but I think he could make an even better one!
Title: Re: Sonic Physics
Post by: willrandship on January 06, 2012, 11:29:40 pm
Indeed, he could :P In fact, why not just put this in with scrolling and a map editor? Even better IMO.
Title: Re: Sonic Physics
Post by: saintrunner on January 06, 2012, 11:37:25 pm
That would be so cool!
Title: Re: Sonic Physics
Post by: Nick on January 07, 2012, 02:53:06 am
linerider for the 8x+? that's awesome :)