1
Programming / Re: Physics Engine Implementation in Roguelikes
« on: May 13, 2013, 01:37:31 AM »You can do Newtonian physics just fine in a grid based game, you'll just be using discrete units of measure based upon a space-time relative to the grid. Which can be rationalized roughly as the space it takes to comfortably occupy a single 'person' and the time it takes for said person to 'move at a brisk pace' between two tiles. As units of measure, we don't need to know what the actual values are, just that they are logical placeholders that serve as an abstraction layer over Newtonian physics.
Your smallest units of measure are 1 tile and 1 tile per turn, so base everything around this, including mass and acceleration.
Decide on whether you want to be fully physical or just use physics for certain effects. In a fully physical game, you need to ensure that an entity is always capable of moving 1 tile's worth based on it's physics-relevant statistics. This is important because you'll need to use it when calculating whether or not you can push into another object's tile.
You're going to probably want to use a state-machine to manage the physical states of agents. Don't use 3D physics, just use abstractions to represent traction. In most cases, if an entity is balanced, then it's forces will be cleared at the beginning of its turn. If not, they should spend their turn recovering balance. Traction should play a role here- for example, if an object waits, you can increase their traction, making it more difficult for them to be moved by other forces. If they're off-balance or in the air/falling, then traction should play no role in whether they recover or not. You'll need different rules for Flying or Floating enemies. An enemy that gets knocked-down might take a hit to their AC, while an enemy that's off-balanced may not be able to move/take action, but wouldn't suffer a penalty doing so.
Use your line-drawing algorithm and rectangles (two xy coords) to represent direction vectors. You'll need this for force calculations that make sense in grids.
Thanks! That all seems to make sense. Could you elaborate on how an solid state machine should best be implemented? I admit I'm not too familiar with them.
A Finite State Machine is just a way of representing different states that an object may be in. You don't actually need any specialist infrastructure to implement them, it's more of a conceptual thing. You may have different states for things like: dead, dying, falling, flying, walking, standing, charging, etc. These states can be implemented as flags or Booleans whereby the functionality of some methods/functions/processes is altered based upon the state. There is no formal way to manage states. Different states are treated in different ways and have different properties, but all represent the same object.
So- for example, we might want an enumerated type to describe the physics states. And then if-statements to modify calculations based upon whatever active physics state that object is in. State Machines are 99% of the time always a smart thing to implement for every game. Let's say the player character fails a traction check against some force applied to him. We just change the physics state and the next time an opponent attacks the player, we use data/values/algorithms relative to that particular state. Say the player gets knocked on the ground- we can change his physics state to 'prone,' which might put him out of LOS for some enemies and easier to hit for nearby enemies.
Alright, thanks again! I have a lot of work to get started on