Search Unity

What do you think the best approach is? Ball Mechanics

Discussion in 'Physics' started by imforshizley, Sep 23, 2019.

?

Did the way I worded my question make enough sense?

  1. I understood your issue

    0 vote(s)
    0.0%
  2. Not really. I'm confused.

    0 vote(s)
    0.0%
  1. imforshizley

    imforshizley

    Joined:
    Sep 22, 2019
    Posts:
    1
    Good day,

    Picture a game of pong where the ball always lands on the center of the receiving racket (no need to move player/racket to where the ball is going). The player presses their "hit" key when they see the ball about to hit their racket. The difference in time between when the ball hits the racket and when the player presses their hit key dictates how much height the ball on the return pass will have. The better the shot (the less time between their key press and the ball hitting the racket), the higher the return pass is, and thus the more time the receiver has to accurately time their own return shot. Make sense?

    What would you argue is the best way to program the ball physics for this concept?

    I've looked at adding force to the ball but with the ball having to always land at the receiver etc, it seems like this may not be the best way.

    Currently I have a Vector3.Lerp interpolating the ball between the two rackets on each FixedUpdate with t being:
    Code (CSharp):
    1. (Mathf.Sin(speed * Time.time) + 1.0f) / 2.0f;
    It works and all, but with this approach, it seems there's no clear way to add height to the trajectory of the ball path. I've considered adding the height to the Y value in the receiving racket object until the ball is half way to the receiving object, and then setting it back to the original Y position of the receiving object but again the approach feels wrong / hacked. Thoughts?

    Thanks!