Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Dribbling a soccer ball with physics

Discussion in 'Scripting' started by matiasjaure, Nov 21, 2011.

  1. matiasjaure

    matiasjaure

    Joined:
    May 27, 2011
    Posts:
    39
    Hi guys! I am working on a project that we are trying a car to dribble a soccer ball and then it can shoot it out. I am dribbling it by changing the transform.position every frame (also tried fixed frame) but when doing that I am loosing physics like movements and also having problems when shooting. So, I was wondering if it is possible to do it using physics, so what I think I would need is:

    1. calculate where the player will be based on his speed / direction (vector)
    2. calculate a force speed / direction (vector), that when applied to the ball will "bump" the ball to where the player will be.
    3. note that this (bump) calculation will need to account for the balls current speed / direction.
    4. note that the balls new speed / direction will have to be entirely based on this bump force to apply.

    Any guess?
     
  2. matiasjaure

    matiasjaure

    Joined:
    May 27, 2011
    Posts:
    39
    Well, I am kind of giving up, maybe the best solution is altering the transform position, but I cannot make it look smooth, at least smooth, it won't look real because the car should dribble the ball even if it is taking a curve.
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You should read the docs, they explain why you wouldn't be able to get it stable by altering the transform.
     
  4. matiasjaure

    matiasjaure

    Joined:
    May 27, 2011
    Posts:
    39
    Any idea on how to achieve without altering transform?
     
  5. Ender

    Ender

    Joined:
    Jun 3, 2011
    Posts:
    72
    There are a lot of ways to do it. You need to decide the specifics of how you want it to work.

    Add a rigidbody to a sphere, and you have the physics you need.. then, how you want the player to be able to act on the sphere is up to you. Make sure you are trying out addrelativeforce and addrelativetorque
     
  6. RingOfStorms

    RingOfStorms

    Joined:
    Oct 23, 2010
    Posts:
    584
    Doing this with physics may be pretty hard, but your could just do dribbling as an animation, and when you shoot it instantiate a basketball that has physics, but the dribble would just be a animation on the player.
     
  7. matiasjaure

    matiasjaure

    Joined:
    May 27, 2011
    Posts:
    39
    It is soccer with cars...

    I could play an animation but let's suppouse that the car turns and the ball has to do the same, how to do that without altering the transform position?

    Many thanks to you all for your help!!.... It is a great community and it is a pleasure to be part of...