4 ms·
Over the years I've found that whenever I want to make something look sort-of-physical, it winds up being quicker and easier to use real physics than to hack up
by fenomas 12y ago
Over the years I've found that whenever I want to make something look sort-of-physical, it winds up being quicker and easier to use real physics than to hack up something that isn't physics-based but looks close enough.
For example, I once made a wave animation just like the one in this post (in 2D but otherwise the same), thusly:
1. Make an array of height values initialized to zero
2. Run a tick() function that applies a spring force between neighboring values, then updates their position/velocity
3. Perturb the middle value by a large amount
Not exactly real fluid mechanics but convincing enough. Perhaps best of all, fine-tuning is easy because the model matches your intuition - if you want the fluid to look more viscous you don't need to guess what to tweak, you just dampen the velocities, etc.
- stegosaurus 12y agoThis post gave me a great nostalgia moment and I imagine others have similar experiences. I remember trying to code a basic platformer at a young age in BASIC or something similar. Moving around the character and jumping are the most basic, essential functions. I tried to reason it out. Ok, so start off slow, after the character has been moving for a bit speed him up. For jumping, add some positive velocity and reverse it after a bit. It took forever to fine tune and still didn't really work that well. I gave up in the end. We didn't have the Internet then and I didn't really think about asking the librarian or similar 'how can i make a character jump about'. Fast forward a few years and my schoolteacher introduced the concept of Newtonian mechanics. Acceleration as a rate of change of velocity; the idea of a ballistic trajectory as a quadratic. Suddenly the problem becomes trivial! That eureka moment I can probably point to as the defining thing that made me choose to study higher level physics. (Part of it was probably being young and not having the reasoning skills I do now - but I also often think about how access to information is so different now. What would the ten year old me have done with access to Wikipedia? Mind boggling.)
- fenomas 12y agoYou may already know this, but actually even a lot of modern game engines use nonphysical methods for moving characters - it's hard to make the character feel responsive using only impulses and friction, etc. I'm working on such an engine at the moment, and it wound up taking some hacking (e.g. I turn off the player's friction when a movement key is pressed - which makes sense when you think about it but seemed nonphysical at first!). With that said, you've reminded me of an example of this. Years ago I was making a "UFO catcher" crane game in Flash, where the user moves a thingy left and right, and an attached crane arm swings freely like a pendulum. At first I thought: this isn't a damned physics simulation, I'll just hack something up. Then I spent probably a whole day trying to get it to not feel so wrong. Then finally I break down and get the formula for pendulum motion off wikipedia, and 15 minutes later it works perfectly - with maybe three lines of physics code. :D
- T-hawk 12y agoThis approach is effective, but is stateful and iterative. There's elegance and quite likely reduced computational load in a functional approach that can give the wave height value with only the inputs of the coordinates and time. That's what the post is going for here. Wave phenomena are a curious intersection of functional and imperative paradigms in real life. Of course the real atoms find their positions by stateful interactions over time, but the behavior should approach the pure mathematical definition of the wave functions.
- fenomas 12y ago> There's elegance and quite likely reduced computational load in a functional approach that can give the wave height value with only the inputs of the coordinates and time. Sure, except there isn't any known closed-form expression that can model water waves in cases like the author is aiming for. (In the steady state water waves are roughly trochoidal, not sinusoidal, if you're interested.) What happened in this article was that the author started with a mental image of what a water drop looks like, then hammered on a sin function until there was a resemblance. That's fine in and of itself, but he might as well have drawn a picture! Whatever resemblance he did or didn't achieve to actual water was a function of how good his mental image was and how long he spent working on the similarity, not a byproduct of the math involved. What's nice about my awful stateful approach is that the physicality arises unbidden. If you code it up it will behave like water all on its own - you won't have to randomly fiddle with it like the article's author. Also, with my version you don't have to start out knowing what water waves look like. It will show you. ;)