How do I ball trajectory prediction

0 favourites
From the Asset Store
Bouncing ball
$9.99 USD
Template for a bouncing ball game, fully documented in comments and video
  • Has anyone successfully created a physics based ball trajectory prediction tracer? the following is about the best I can come up with but it's not really good enough, for obvious reasons.

  • Prediction, like anticipate the ball movement? Your example is just a trail. You can spawn a "motion blur" instead.

    this is another approach ... ry_v2.capx

  • This version is even better ... ry_v3.capx

    It only works if only one ball is at the screen, those 2 variables ball_astX and ball_lastY are global, if many balls are on screen, one will overwrite the other value. Instead you can create instead of global variables, instance variables, and for the square trail assign an instance variable having the UID of the ball that create it <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile"> (parent)

  • I was a little un-descriptive in my first post with the word tracer, what I'm after is a way to create a path showing the trajectory the ball will travel before it's shot including after hitting objects kinda like in peggle. That's a great tracer effect though, thanks for sharing will be using that.

  • AHA, I see

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I will try to make you the prediction also

  • I tried creating the prediction by giving a biger impulse ti increase speed, but all the variables need to be changed to create the same trajectory, since it all depends of time, and C2 precision, everything goes wrong. Since trajectory depends on gravity and time, if you want to make a game without gravity involved it can make good prediction.

    I aso tried with setting the timescale, but no luck ... ry_v4.capx

    P.S. change the global variable Gravity from 10 to 0 to see that prediction is much better.

  • There's an example here that draws the path of the object.

    It doesn't do collisions though.

  • R0J0hound Cool post. Thanks

  • Thanks guys unfortunately at this time my maths skills are terrible you obviously know what your doing and if collisions are difficult for you to figure out, it would be far beyond me. I was attempting to create a Peggle clone, have learn't tons up to this point but I think a game like this really needs the ball prediction with collisions. I'll have a think and in the mean-time start some more experiments, love tinkering around with Construct. I find it much easier to learn by trying to re-create a game I already know and love.

  • I actually had a look on Peggle more carefully. From what I can see from youtube, the prediction only shows the trajectory until the first obstacle is reached, to show that instantly it can be shown without physics. I am also bad at math. but how I could do it is to use R0J0hound example to draw that parabola. create balls along it, and hide the ones after the first one hits the obstacle. Is more complicated than this, but your cannon will have to be a tangent to that parabola. I am sure that if you ask R0J0hound , it will help you with that.

  • Collisions would basically mean re-creating the physics behavior with events to be able to step the physics multiple times. Which isn't ideal at all. The way peggle probably did it was leverage the physics engine itself to do many simulation steps at once to instantly trace a path. C2's physics behavior only steps automatically per frame. It's not possible to step it manually.

    For now you could get away with continuously launching balls to trace the path. It wouldn't be instant but it would show the path.

  • Cant you just spawn basically a clone of the ball, have it do its bounces really fast, and then display path? basically do what the ball is going to do really really fast, and show a line where its been?>

  • cs2curious I tried that , but if you launch the ball faster, the trajectory changes, (it becomes more linear at the beginning), you also have to adjust the gravity to match the normal path.

  • Yeah, just making it faster changes where the ball would go and how much it bounces. It wouldn't match the path the ball would actually follow.

    Here's a way to predict where the ball would go, including bounces. The drawback is it doesn't work with the physics behavior, instead I just used a js physics library so I could do many simulation steps at once. The second issue is that's all I made it do. For a complete game it would need to switch between predicting the path and actually moving.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)