Ball Physics Simulation

CluckFox

Active member
A brief discussion on Discord about making a golf game got me thinking about Physics. @CutterCross pointed out the following video as a point of reference.


I'd like to make some test ROMs in an attempt to implement my own ballistic physics code for use in fellow NESMakers' future games. The gravity-enabled physics engines that ship with NESMaker's Platform/Vania modules can already do at least 80% of the work. The rest is optical illusions and only occasional use of "slow" math calculations.
 

Bucket Mouse

Active member
Water physics aren't nearly as hard as ball physics. For water physics you just make the gravity more floaty.

Anyway, let's keep this on ball physics because I'd like to see this too.
 

CluckFox

Active member
The first physical scenario I'm working on is the ball deflecting off of a hill. Based on the Nesert Golfing video this has two challenges:
  • Detecting a collision along a slope
  • Computing the speed & direction of the ball upon collision
For the computation I'm starting with the Wikipedia article on elastic collisions in 2 dimensions between 2 moving bodies. The sine and cosine expressions can be resolved either with lookup tables or by floating-point division (FDIV) operations. The number of FDIV and floating-point multiplication (FMUL) needed appears manageable when one of the two bodies is stationary.

This leads to the first challenge of detecting a collision on a slope: I intend to cheat by using special background tile collisions to spawn an invisible "paddle" monster at a more precise location in front of the ball, and performing the computation & deflection in the sprite collision code. Remember the Trampoline tile in the tutorials?

I'll post a ROM demonstrating balls-on-hills, hopefully someday soon. This is all in my head right now and I'm doing this as a hobbyist, not an engineer.
 

Knietfeld

Member
The physics in NESert Golfing are pretty cool. I didn't attempt a golf game but I was playing with bouncing physics a year ago.
This was my attempt.
Back in version 4.1.5 I was making a metroidvania style game that I implemented some ball physics in. It started as my Byte-Off 2019 submission but I got caught up adding features and just had a bunch of janky test rooms when submission time came so I just didn't submit it.

View: https://youtu.be/JJSZKUDUcPc




The different types of balls could have one of three levels of bounciness and I made them bounce off of walls and the floor, then I got the bright idea to make slopes. Figuring out how to make the balls bounce off of slopes was a fun challenge. My solution was much simpler and way less accurate than NESert Golfing. I think what I did was, when an object hit any kind of solid it would check if it was a slope tile and then it would just add a number to the horizontal speed depending on the kind of slope. It had it's problems but I thought it was pretty awesome at the time. I still plan on finishing that game eventually, and I'll probably change up the whole way collisions work again when I do. Maybe I can do a slightly more intelligent method next time that doesn't fling the bouncy eyeballs all over the place off of slopes.
 

Logana

Well-known member
The physics in NESert Golfing are pretty cool. I didn't attempt a golf game but I was playing with bouncing physics a year ago.
This was my attempt.
Back in version 4.1.5 I was making a metroidvania style game that I implemented some ball physics in. It started as my Byte-Off 2019 submission but I got caught up adding features and just had a bunch of janky test rooms when submission time came so I just didn't submit it.

View: https://youtu.be/JJSZKUDUcPc




The different types of balls could have one of three levels of bounciness and I made them bounce off of walls and the floor, then I got the bright idea to make slopes. Figuring out how to make the balls bounce off of slopes was a fun challenge. My solution was much simpler and way less accurate than NESert Golfing. I think what I did was, when an object hit any kind of solid it would check if it was a slope tile and then it would just add a number to the horizontal speed depending on the kind of slope. It had it's problems but I thought it was pretty awesome at the time. I still plan on finishing that game eventually, and I'll probably change up the whole way collisions work again when I do. Maybe I can do a slightly more intelligent method next time that doesn't fling the bouncy eyeballs all over the place off of slopes.
sir i kindly request you share you slope code
 

Bucket Mouse

Active member
Dunno if it would still work, if it was written in 4.1. But with a little modification, it might, Also, you had enough there to make a pinball game.
 

Knietfeld

Member
It would all have to be totally rewritten I'm pretty sure but the basic concepts would still apply. I haven't messed with tile collisions a whole lot yet in the newest version but I think I looked over it early on and it was quite different.

Oh, and I figured eventually I'd have some mini games in it that used those unique mechanics, maybe something like a pinball game.
 

CluckFox

Active member
In a much more modest development, I turned the Sprite HUD from the LR Platformer module into a golf swing meter and club selection menu.
wlCPi5epml.gif
 

CluckFox

Active member
I got the ball to bounce around the room using the swing meter. This will eventually be the subject of another tutorial, but the code is still in the "crashing" phase of development.

ballprototype.gif
 

CluckFox

Active member
Aside from the physics I'm also working on a scoring system. It uses a signed 8-bit integer to keep the player's score. The "par" and "handicap" are stored in each level's screen bytes. Handicap is not a traditional golf handicap, but affects the number of swings you can take on a level before it forces you to give up.
 
Top Bottom