Saturday 9 January 2016

Sketchy physics simulations.

Today I attempted to wrap my head around portals...




In my simulation, when the spheres reach the bottom of the tube, they are teleported to the right hand surface of the cylinder. Maintaining speed but changing the sphere's direction.

Initially I ran into a problem of them gaining energy over time, since the force which pushed them from the portal is proportional to the velocity it hits the bottom and the position of the ball along the horizontal axis.


Then after some thinking with my trusty whiteboard...


I realised that it was because I wasn't forcing the spheres out with the same amount of energy the spheres had at the bottom of the tube! Momentum!

Another issue I had was that spheres would converge, I figured it was something to do with the way I was applying drag to the velocity of the spheres. After all portals can't exist in a real physical model without hacks can they? In my opinion I think this one looks the most... real. Since everything loses energy it makes sense that this would happen "in real life" to me?

Here's what I mean:

But i prefer the look of things when we bend physics a bit, here's what I have now! (Beware it has music)


I'm happy with this result and hopefully in the next few days I can iron out all the issues with the collision model, and explain fully how I did it. Right now the collisions are kind of hacky and not optimised. In brief it works through the distance of any sphere to the Y axis and the direction from that sphere to the Y axis.



It was really fun getting into physics concepts again! It has been ages since i have implemented things like this. Still my code is quite expensive, it uses a lot of normalising and distance calculations which I want to optimize.

See you soon!

Here's a link to the program so far: Sphere Simulation


No comments:

Post a Comment

The difference between class and object.

 The difference between class and object is subtle and misunderstood frequently. It is important to understand the difference in order to wr...