Mastering Parabolic Motion in Online Games: Understanding Physics and Gravity

  • Context: Undergrad 
  • Thread starter Thread starter Joe390
  • Start date Start date
  • Tags Tags
    Motion
Click For Summary

Discussion Overview

The discussion revolves around the application of physics principles, particularly parabolic motion and gravity, in the development of online games. Participants explore kinematic principles, numerical methods for simulating motion, and the effects of forces like air resistance and wind on trajectories.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant notes the use of Newtonian physics to generate vertical parabolas for simulating gravity in games and questions the appropriate measurement for gravity in a game context.
  • Another suggests simulating differential equations to generate positions along the arc, allowing for the inclusion of air resistance and wind effects, while acknowledging potential accumulation of error.
  • There is a discussion about calculating motion using time steps, with one participant proposing that the parabola is a result of iterative calculations rather than needing an explicit equation.
  • Participants discuss the second derivative of motion and how to incorporate various forces, including air resistance, into their calculations, with differing opinions on the proportionality of air resistance to velocity.
  • Concerns are raised about energy conservation violations in numerical methods, with examples provided to illustrate how finite time steps can lead to discrepancies in energy calculations.
  • Some participants propose using averaging methods to improve accuracy in displacement calculations, while others mention the limitations of these methods when acceleration is not constant.
  • A participant shares their experience with trajectory calculations in an external ballistics program, indicating practical applications of the discussed principles.
  • One post introduces a more abstract concept regarding the inverted parabola and the sum of forces acting on a body during a fall, though it lacks clarity and context.

Areas of Agreement / Disagreement

Participants express a range of views on the best methods for simulating motion and the implications of numerical methods on energy conservation. There is no clear consensus on the most effective approach or the correct treatment of air resistance.

Contextual Notes

Limitations include assumptions about constant acceleration, the choice of time steps, and the potential for error accumulation in numerical methods. The discussion also reflects varying levels of familiarity with physics concepts and programming techniques.

Who May Find This Useful

Game developers, physics enthusiasts, and those interested in numerical methods for simulating motion in interactive environments may find this discussion relevant.

Joe390
Messages
5
Reaction score
0
I've been trying to make an online game using the rules of physics. If I'm not mistaken this flash game uses Newtonian physics by generating a vertical parabola to simulate gravity. I also realize that acceleration in the x direction can occur. Are there any other sort of kinematic principles I should take into account? Also I know that gravity on Earth is about 10. What is it for a typical game such as this? I guess it would be measured in pixels/sec^2. Any input is much appreciated.

Thanks so much
 
Physics news on Phys.org
Since you will need to generate the position at each point in the arc, you don't have to have exact solutions for the path of motion; you can simulate the differential equations. This means you can easily take into account air resistance, and maybe a wind blowing. The downside is there may be a small accumulation of error.
(Back in the early days of PCs, there was a free game written in Basic that involved gorillas throwing exploding bananas at each other across a city skyline. There was something weird about the trajectories, so I looked at the code. Horizontal wind had been implemented as some kind of lateral gravity, accelerating without limit!)
 
Joe390 said:
I guess it would be measured in pixels/sec^2
I would guess pixels/(timestep)^2 where the timestep is something like 1/50s. Using those timesteps, you can calculate the velocity and the position for each step. The parabola does not need any representation in the code, it is just the result of the step-by-step calculation.

uses Newtonian physics
With the option to accelerate horizontal and vertical in flight ;).
 
haruspex said:
Since you will need to generate the position at each point in the arc, you don't have to have exact solutions for the path of motion; you can simulate the differential equations. This means you can easily take into account air resistance, and maybe a wind blowing. The downside is there may be a small accumulation of error.
(Back in the early days of PCs, there was a free game written in Basic that involved gorillas throwing exploding bananas at each other across a city skyline. There was something weird about the trajectories, so I looked at the code. Horizontal wind had been implemented as some kind of lateral gravity, accelerating without limit!)

So if y = 5t - 5t^2 the differential equation is dy/dt = 5 - 10t. How do I account for air resistance and wind blowing. The horizontal wind error sounds like something that definitely might happen if I approach the problem this way. Is there a better way maybe? Because Robot Unicorn Attack and other similar games are not glitchy at all.

mfb said:
I would guess pixels/(timestep)^2 where the timestep is something like 1/50s. Using those timesteps, you can calculate the velocity and the position for each step. The parabola does not need any representation in the code, it is just the result of the step-by-step calculation.


With the option to accelerate horizontal and vertical in flight ;).

Yeah I now understand this. I thought you need an explicit equation for position, but now I see that the parabola is just a result of the step by step calculation.
 
Calculate the second derivative: a=\frac{d^2y}{dt^2}=-10
You can add all sorts of forces to this acceleration. Air resistance would be proportional to (v-vwind)^2 for reasonable velocities, for example.

Now, for each time step, keep track of horizontal velocity v and position y. If the object jumps, set its initial velocity v0 to some value, corresponding to the "jumping capability" of the object. The position y0 is simply the location where the jump happens. Now, the iterative formulas can be written as:

v_i=v_{i-1}+a_{i} dt
y_i=y_{i-1}+v_{i} dt

Those formula violate energy conservation, but they are a very simple way to calculate the position and velocity. The Runge–Kutta methods give a smaller error.
 
mfb said:
Calculate the second derivative: a=\frac{d^2y}{dt^2}=-10
You can add all sorts of forces to this acceleration. Air resistance would be proportional to (v-vwind)^2 for reasonable velocities, for example.

Now, for each time step, keep track of horizontal velocity v and position y. If the object jumps, set its initial velocity v0 to some value, corresponding to the "jumping capability" of the object. The position y0 is simply the location where the jump happens. Now, the iterative formulas can be written as:

v_i=v_{i-1}+a_{i} dt
y_i=y_{i-1}+v_{i} dt

Those formula violate energy conservation, but they are a very simple way to calculate the position and velocity. The Runge–Kutta methods give a smaller error.

This is great thanks. I didn't realize that air resistance is proportional to (v-vwind)^2. For some reason I was under the impression that air resistance is proportional to k*v where k is a constant. Would you recommend 4th order Runge-Kutta to solve these iterations. In what way do those formulas violate energy conservation? This is very interesting to me.
 
They violate energy conservation with finite time-steps. As an example, drop an object from a height of 30m with 0m/s initial velocity, and approximate g=10m/s^2. As time step, I use 1s (very large!). The pairs (velocity,position) are then given by:

(0,30)
(10,30-10=20)
(20,20-20=0) -> hits the floor with 20m/s.
An object with mass 1kg would have an initial potential energy of mgh=300J, and a final kinetic energy of 1/2 mv^2 = 200J. The difference went in the bad approximations in the time steps.

A better way to calculate the displacement would be to take the average of the old and the new velocity:
y_i=y_{i-1}+\frac{v_i+v_{i-1}}{2}dt

Same situation again:
(0,30)
(10,25)
(20,10) -> now, 20m/s corresponds to a drop of 20m, which is consistent with energy conservation.
(30,-15) -> well, hit the floor somewhere in between.

If the acceleration is not constant, this will lead to deviations again, but for constant acceleration it works.
 
mfb said:
They violate energy conservation with finite time-steps. As an example, drop an object from a height of 30m with 0m/s initial velocity, and approximate g=10m/s^2. As time step, I use 1s (very large!). The pairs (velocity,position) are then given by:

(0,30)
(10,30-10=20)
(20,20-20=0) -> hits the floor with 20m/s.
An object with mass 1kg would have an initial potential energy of mgh=300J, and a final kinetic energy of 1/2 mv^2 = 200J. The difference went in the bad approximations in the time steps.

A better way to calculate the displacement would be to take the average of the old and the new velocity:
y_i=y_{i-1}+\frac{v_i+v_{i-1}}{2}dt

Same situation again:
(0,30)
(10,25)
(20,10) -> now, 20m/s corresponds to a drop of 20m, which is consistent with energy conservation.
(30,-15) -> well, hit the floor somewhere in between.

If the acceleration is not constant, this will lead to deviations again, but for constant acceleration it works.

If the acceleration is not constant, you can do the same with acceleration values: average the old and the new acceleration before you compute the new velocity. This will improve the result, but still lead to deviations if the changes in acceleration are non-linear.
 
A recursive trajectory calculation is fairly easy to setup using the time gradiant and the acceleration of gravity. Depending on initial velocities and the drag coefficient of the object you can very accurately compute the path.
I did this for an external ballistics program in C back when DOS was the operating system of choice. I believe I still have it somewhere but right now everything is being packed up for our move to a new home.

Paul
 
  • #10
you probably got somebody who figured out you could plug x-y data in there computer game instead of math calculating equations.

the inverted parabola works for the sum of forces (x-y-z) throughout a fall with the opposite end of the foci representing the sum of horizontal forces exerted on the body at all times
 
Last edited:
  • #11
mfb said:
They violate energy conservation with finite time-steps. As an example, drop an object from a height of 30m with 0m/s initial velocity, and approximate g=10m/s^2. As time step, I use 1s (very large!). The pairs (velocity,position) are then given by:

(0,30)
(10,30-10=20)
(20,20-20=0) -> hits the floor with 20m/s.
An object with mass 1kg would have an initial potential energy of mgh=300J, and a final kinetic energy of 1/2 mv^2 = 200J. The difference went in the bad approximations in the time steps.

A better way to calculate the displacement would be to take the average of the old and the new velocity:
y_i=y_{i-1}+\frac{v_i+v_{i-1}}{2}dt

Same situation again:
(0,30)
(10,25)
(20,10) -> now, 20m/s corresponds to a drop of 20m, which is consistent with energy conservation.
(30,-15) -> well, hit the floor somewhere in between.

If the acceleration is not constant, this will lead to deviations again, but for constant acceleration it works.

Now I think I get it. With a large time step energy is not conserved. If the time step is decreased, and approaches 0 seconds then is energy conservation maintained?
 
  • #12
In the limit dt->0, energy is conserved with all (reasonable) formulas, right.
 
  • #13
lol for using robot unicorn attack as an example of a game that uses parabolic motion. One question I have is how do you calculate the initial angle of the projectile? I think is the inverse tangent of initial velocity in the y direction divided by velocity in the x direction. How does acceleration affect the initial jump angle and the range of the projectile.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 10 ·
Replies
10
Views
5K