• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 04:31
CEST 10:31
KST 17:31
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Code S RO8 Preview: herO, Zoun, Bunny, Classic4Code S RO8 Preview: Rogue, GuMiho, Solar, Maru3BGE Stara Zagora 2025: Info & Preview27Code S RO12 Preview: GuMiho, Bunny, SHIN, ByuN3The Memories We Share - Facing the Final(?) GSL47
Community News
BGE Stara Zagora 2025 - Replay Pack2Weekly Cups (June 2-8): herO doubles down1[BSL20] ProLeague: Bracket Stage & Dates9GSL Ro4 and Finals moved to Sunday June 15th13Weekly Cups (May 27-June 1): ByuN goes back-to-back0
StarCraft 2
General
Code S RO8 Preview: herO, Zoun, Bunny, Classic Jim claims he and Firefly were involved in match-fixing The SCII GOAT: A statistical Evaluation DreamHack Dallas 2025 - Official Replay Pack BGE Stara Zagora 2025 - Replay Pack
Tourneys
[GSL 2025] Code S:Season 2 - RO8 - Group A RSL: Revival, a new crowdfunded tournament series SOOPer7s Showmatches 2025 Sparkling Tuna Cup - Weekly Open Tournament Sea Duckling Open (Global, Bronze-Diamond)
Strategy
[G] Darkgrid Layout Simple Questions Simple Answers [G] PvT Cheese: 13 Gate Proxy Robo
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 477 Slow and Steady Mutation # 476 Charnel House Mutation # 475 Hard Target Mutation # 474 Futile Resistance
Brood War
General
BW General Discussion BGH auto balance -> http://bghmmr.eu/ FlaSh Witnesses SCV Pull Off the Impossible vs Shu StarCraft & BroodWar Campaign Speedrun Quest Will foreigners ever be able to challenge Koreans?
Tourneys
[BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET [ASL19] Grand Finals NA Team League 6/8/2025 [Megathread] Daily Proleagues
Strategy
I am doing this better than progamers do. [G] How to get started on ladder as a new Z player
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Beyond All Reason Path of Exile What do you want from future RTS games?
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread UK Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Vape Nation Thread
Fan Clubs
Maru Fan Club Serral Fan Club
Media & Entertainment
Korean Music Discussion [Manga] One Piece
Sports
2024 - 2025 Football Thread Formula 1 Discussion NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
A Better Routine For Progame…
TrAiDoS
StarCraft improvement
iopq
Heero Yuy & the Tax…
KrillinFromwales
I was completely wrong ab…
jameswatts
Need Your Help/Advice
Glider
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 28371 users

Student Game Dev Part Eleven - Fixing the Physics

Blogs > Soan
Post a Reply
Soan
Profile Blog Joined August 2010
New Zealand194 Posts
February 07 2014 00:43 GMT
#1
+ Show Spoiler [Previous parts] +
Part One - It begins
Part Two - Technical Foundation
Part Three - Game Design
Part Four - Input and Physics
Part Five - More Physics Things
Part Six - Even More Physics
Part Seven - User Interface
Part Eight - UI and the Editor
Part Nine - Editor Progress
Part Ten - Progress, and videos


This Week
Hello again TeamLiquid! Welcome back to my blog about the development of The Adventures of Sam the Pirate, the 2D platformer I'm creating as the final game project for my Bachelor of Software Engineering degree. Last week I talked about the progress I'd made, and talked a bit about performance issues again. This week I'll be talking about the fixes I've made to the physics, and talking about performance again. Also finally got around to adding a couple of debug console commands, namely loading a level from file and toggling physics debugging rendering on and off.

Fixed Physics
I managed to successfully improve the movement, and fix a couple of physics bugs this week. At the start of the week, I had been a little worried about managing to fix it by the end of the week, when the last alpha milestone is due, but it was successfully done by the end of Wednesday. Having it fixed by then has allowed me to relax a little for the last couple of days, and take care of some smaller things, as I don't want to work on anything major in case I irrevocably break things before the milestone.

Most of the fixing for the physics came from adjusting what happened in collision reactions. The SDL function I'm using to detect collision between two rectangles returns another rectangle that contains the position, width, and height of the intersection. Originally I had been using this to determine how far to correct the players position, as I already knew what direction the player was, whether it be left/right, or above/below. Now, the players position is corrected by a fixed amount, with this amount being determined by the size of the tile, and the size of the players sprite.

When I first started writing the physics code, each physics actor had a single flag for whether or not they had collided with another actor. I changed this to having separate flags for vertical and horizontal collisions, and then wondered why I had ever done it with the single flag in the first place, as two made much more sense given that the physics is based around rectangles. So if the player is above/below a tile, that is a vertical collision, to the left/right is a horizontal collision. I also adjusted the collision response in such a way that on a vertical collision, when the players position is corrected, they are still colliding, but only just. Visibly they player does not look like he is colliding with anything. Both of these changes allowed me to fix the jittering, as that was being caused by the player colliding, being moved up, not colliding anymore and being forced down by gravity, colliding again, moving up again, etc. Now, as long as the player stands on a platform, they are always in state of vertically colliding and so gravity will not take effect.

There are still a few bugs, but they are relatively minor and not particularly game breaking. The first involves trying to run into a wall, you get the same kind of jittering on the player that used to happen when the player was on a platform, but more pronounced. The second involves corner tiles, depending on how you hit the corner tile, you could end up inside it, or teleported to the top of it. If you end up inside it you can still move out of it however, so a player wouldn't get stuck. These are all fixable, and will be fixed at some point.

The third bug, might end up remaining unfixed as a feature. When the player falls, say they ran off the edge of a platform, they can jump while in mid air. You can't double jump in Sam the Pirate, so while a jumping animation is being run hitting jump again will not do anything. However hitting a tile from below changes the players animation to a running animation, so it's possible to chain jumps for some distance, as long as you're hitting the bottom of a tile. This bug/feature has also made me realise I don't have a falling animation, although maybe the jump animation that plays while you're in the air is also a falling animation, in which case fixing this bug/feature will disable being able to jump while falling. Maybe I could fix it and keep this effect, as it could be interesting. You can see it in the new gameplay video below:



What do you guys think? Fix or keep jumping while falling?

Performance
I tested the game on my laptop at home again, this time I managed to get around 20 fps when in debug mode, which is a nice improvement. Still not 100% sure what I did to improve this, but it must have something to do with the changes I've made in the physics code I guess? I dunno. I did play around with some of the code in the physics, what order things were being processed etc, so that must be where it came from.

I've also possibly come up with a method of rendering all the static tiles in the level at once, rather than individually like I currently am. I haven't been too sure how to do this in SDL until now, but I think that I can probably render each static tile into an SDL surface, generate an SDL texture from this surface, and then use that texture to render into the main rendering surface. This would certainly save a lot of time on the rendering side, but would increase the initial load time for a level.

At some point soon, I should also look at doing some profiling, and finding out where the bottleneck actually is. Right now I think it is the rendering, but it could also be on the processing side, as there are quite a large number of tiles. I need to start timing things and finding out how long each takes.

What's next?
Over the next week, I'll look at changing the static tile rendering as I mentioned earlier, and work on the editor further, as it's the next important piece of the puzzle I need. The next step for the editor is being able to place other level elements, like enemies and moving platforms etc. I've also got a demonstration on Monday to the schools games faculty, but I feel pretty good about that as I think I'm mostly on track.

Keep up to date!
Be sure to follow me on Twitter, and like the Facebook page to stay up to date on future content and blog posts when they happen. If you have any questions don't hesitate to ask, either through Twitter or Facebook!

****
Please log in or register to reply.
Live Events Refresh
Next event in 59m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Livibee 143
mcanning 141
ProTech56
StarCraft: Brood War
Mong 1456
BeSt 1241
Sea 1028
actioN 306
EffOrt 273
Leta 113
Sharp 46
sSak 31
hero 24
Nal_rA 23
[ Show more ]
ivOry 7
HiyA 6
NaDa 6
zelot 3
Dota 2
BananaSlamJamma386
XcaliburYe368
Fuzer 219
League of Legends
JimRising 599
Counter-Strike
Stewie2K1232
shoxiejesuss726
Heroes of the Storm
Khaldor155
Other Games
C9.Mang0882
XBOCT442
crisheroes339
Happy275
Mew2King161
Lowko15
Organizations
Dota 2
PGL Dota 2 - Secondary Stream5355
Other Games
gamesdonequick620
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• LUISG 34
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Airneanach7
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Stunt443
• HappyZerGling101
Other Games
• WagamamaTV51
Upcoming Events
GSL Code S
59m
herO vs Zoun
Classic vs Bunny
The PondCast
1h 29m
OSC
12h 29m
Replay Cast
15h 29m
OSC
15h 29m
WardiTV Invitational
1d 2h
OSC
1d 4h
Korean StarCraft League
1d 18h
SOOP
2 days
sOs vs Percival
CranKy Ducklings
2 days
[ Show More ]
WardiTV Invitational
2 days
Cheesadelphia
2 days
CSO Cup
2 days
GSL Code S
2 days
Sparkling Tuna Cup
3 days
Replay Cast
3 days
Wardi Open
4 days
Replay Cast
4 days
Replay Cast
5 days
RSL Revival
5 days
Cure vs Percival
ByuN vs Spirit
RSL Revival
6 days
herO vs sOs
Zoun vs Clem
Replay Cast
6 days
Liquipedia Results

Completed

CSL Season 17: Qualifier 2
BGE Stara Zagora 2025
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
BSL Season 20
KCM Race Survival 2025 Season 2
NPSL S3
Rose Open S1
CSL 17: 2025 SUMMER
2025 GSL S2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025
YaLLa Compass Qatar 2025
PGL Bucharest 2025
BLAST Open Spring 2025

Upcoming

Copa Latinoamericana 4
CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
K-Championship
SEL Season 2 Championship
Esports World Cup 2025
HSC XXVII
Championship of Russia 2025
Murky Cup #2
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.