A Little Physics in 3D
In Chapter 8, we developed a very simple point-mass based physics model in 2D. Here's the good news: everything works the same in 3D!
- Positions are now 3D vectors instead of 2D vectors. We just add a z-coordinate.
- Velocities are still expressed in meters per second on each axis. We just add one more component for the z-axis!
- Accelerations are also still expressed in meters per second squared on each axis. Again, we just add another coordinate.
The pseudocode in Chapter 8, where we described a physics simulation update, looked like this:
Vector2 position = new Vector2();
Vector2 velocity = new Vector2();
Vector2 acceleration = new Vector2(0, -10);
while(simulationRuns) {
float deltaTime = getDeltaTime(); velocity.add(acceleration.x ...
Get Beginning Android 4 Games Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.