Search Unity

how to force the ball after collision with bat?

Discussion in 'Getting Started' started by moaazafzal, Jan 31, 2019.

  1. moaazafzal

    moaazafzal

    Joined:
    Apr 15, 2016
    Posts:
    4
    Making a cricket 3d game. when ball touches the bat it stop however where bat touches.
    my question is how to force the ball where the bat moves.
    sorry for bad English.
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    I don't have specific information on how to do this, but one thing I can offer is perhaps a different way of thinking.

    Most games fake things. The more important it is to the gameplay, the more it's faked.

    By this I mean although Unity has a physics system, you probably don't want to use that straight out of the box for your ball movement if the way the ball moves is really important for your game. Baseball games don't have a bat with a cylinder collider and ball with sphere collider that just have both move and react to each other, for example. When a batter makes contact with the ball, the game would do some calculations to determine where on the ball contact was made, the speed and angle of the bat, the spin of the ball, etc... to determine the ball's outward trajectory. And probably none of it based on the actual physical properties of those objects as they exist in the game, but rather as a series of properties of data behind the scenes.

    Maybe another better example: shooting games don't simulate the way the gun actually works. As in, the player clicks the Fire button and the game simulates the trigger mechanism releasing the hammer, which then strikes the firing pin, which ignites the propellant, which then expands and forces the bullet down the barrel towards its target. Instead, you can assume all that stuff happens and figure out a few numbers associated with the result, and use those to determine the important part of your sim: where the bullet goes.

    - - -

    So for your game, when the player swings the bat and makes contact, consider figuring out how hard they were swinging, where they hit the ball, and then use that information to "switch off" the bat and just do an ApplyForce on the ball in the appropriate vector.

    Does that make sense?
     
  3. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    Could you go into more details, on this part.:)
     
  4. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    :confused:

    Well, I mean... Like, you'd definitely use math, and... other things... to figure it out, and... then you'll be saved.

    Something like this, I guess.
     
    BrandyStarbrite likes this.