1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Calculating trajectory for a throw (Game-programming)

  1. Dec 15, 2014 #1
    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:


    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.

    Best regards,
  2. jcsd
  3. Dec 16, 2014 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper
    Gold Member
    2017 Award

  4. Dec 16, 2014 #3


    User Avatar
    Science Advisor

    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.
  5. Dec 17, 2014 #4
    Thanks a lot for the reference. I replaced my previous calculation of the impulse to the formula found on that wiki link.

    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??

    Best regards,
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook