Calculating trajectory for a throw (Game-programming)

In summary, Oyvind was trying to figure out how to plot a trajectory for a snowball being thrown, but he was having trouble.
  • #1
OyvindAndersson
2
0
Hello, and +1 for this great forum!

I have encountered a small problem in my way of creating a small game. I have a snowball that is being thrown by the player. The dynamic variables from the input of the player are: Force and angle (between 90 : -90 degrees). At the moment I apply the force like so:

16007435626_603dba6405_o.jpg


The force is spent in 2 dimensions (Z and Y axes for up/down, left/right). Anyway, that is working quite well, and I'm happy with the result. But what I need is to draw some graphics on the screen to simulate the trajectory the ball will take before it is thrown. Not all the way, but an indication of how the trajectory will be.

If you know the game "Peggle" (perhaps angry birds also?), it is much like that.

Variables I have: Point of launch (vector), angle/direction, gravity vector, and the force that is divided between both the Z and Y axes and mass of the ball (kg).

If any of you could help me calculate the arc of the trajectory so that I could visualize a part of it, I would be very grateful. Alas my math skills does not stretch that far.Oyvind
 
Physics news on Phys.org
  • #3
OyvindAndersson said:
If any of you could help me calculate the arc of the trajectory so that I could visualize a part of it
A trajectory with no drag is quite simple to compute, as shown in the wiki link.

But ideally that engine you use would support a background physics simulation, where you can add a virtual object to your world and simulate a few seconds of it, in every frame of your actual simulation, to plot it's predicted motion. That would encompass additional affects you might add to your game, like aero drag and wind. You should ask in a forum specific to that engine if there is a functionality like that.
 
  • #4
Thanks a lot for the reference. I replaced my previous calculation of the impulse to the formula found on that wiki link.

@A.T.
I'm having some trouble implementing the tracing, however. The physics backend in Unreal Engine 4 is somewhat closed off, and the documentation for what is currently exposed is lacking. Therefore I have some trouble simulating the throw virtually.

The upside however, is that I have not - and will not - add in wind. The only thing affecting it is the gravity, initial velocity and the mass of the ball.

I tried to get the displacement at different lengths, but I must have borked the forumla somehow. I think [time] is what is confusing me a bit. Since I'm not doing any simulations, how would I present time??Øyvind
 
  • #5
,

Thank you for sharing your question with us. Calculating the trajectory for a throw in game programming can be complex, but it is definitely achievable. Here are some steps you can follow to help you in this process:

1. Determine the initial velocity of the snowball based on the input from the player (force and angle). This can be calculated using the formula: v = u + at, where v is the final velocity, u is the initial velocity (which is 0 in this case), a is the acceleration (in this case, the force divided by the mass of the ball), and t is the time.

2. Use the initial velocity to calculate the position of the snowball at different time intervals. This can be done using the formula: s = ut + 1/2at^2, where s is the position, u is the initial velocity, a is the acceleration, and t is the time.

3. Repeat this calculation for multiple time intervals to get a series of positions that the snowball will pass through.

4. Plot these positions on a graph to get an idea of the trajectory. You can also use this data to draw graphics on the screen to simulate the trajectory.

5. Keep in mind that the trajectory will be affected by the force of gravity, so you will need to incorporate that into your calculations as well.

I hope this helps you in your game programming journey. Good luck!
 

1. How is the trajectory of a throw calculated?

The trajectory of a throw is calculated using a mathematical formula that takes into account the initial velocity, angle of release, and gravitational force. This formula is known as the projectile motion equation and is commonly used in game-programming to simulate real-life physics.

2. What factors can affect the trajectory of a throw?

The trajectory of a throw can be affected by a variety of factors such as air resistance, wind speed and direction, and the shape and weight of the object being thrown. These factors can cause variations in the trajectory and make it more challenging to accurately predict the path of the throw.

3. How accurate is the calculated trajectory in game-programming?

The accuracy of the calculated trajectory in game-programming depends on the complexity of the physics engine being used. In simpler games, the trajectory may be approximated using a basic formula, while in more advanced games, more complex algorithms and simulations are used to achieve a more accurate and realistic trajectory.

4. Can the trajectory of a throw be altered in real-time during gameplay?

Yes, the trajectory of a throw can be altered in real-time during gameplay. This can be done by adjusting the initial velocity or angle of release, or by factoring in external factors such as wind or air resistance. Many games also allow players to manipulate the trajectory through user input, such as aiming and throwing at different angles.

5. How important is calculating trajectory in game-programming?

Calculating trajectory is an essential aspect of game-programming, especially in games that involve throwing objects or projectiles. A realistic and accurate trajectory adds to the overall immersion and gameplay experience, making it an important factor to consider in game design and development.

Similar threads

Replies
1
Views
797
Replies
14
Views
1K
Replies
3
Views
2K
  • Introductory Physics Homework Help
2
Replies
38
Views
1K
  • Introductory Physics Homework Help
Replies
3
Views
754
Replies
1
Views
4K
Replies
2
Views
4K
Replies
4
Views
2K
Replies
2
Views
1K
Back
Top