ball shooting passing through

Hi all,

I am making a cube kicking a ball. It is a side scroller game, some movements are constrained. But allot of times when the cube is moving fast he misses the ball (he goes through the ball)

Scripts:

cube:

  • Rigidbody

  • Drag Rigidbody

  • Magnitude

    var other : Transform;

    var closeDistance = 5.0;

    static var sqrLen = 0;

    function Update() {

        // square the distance we compare with
        if( sqrLen < closeDistance*closeDistance ){
         sqrLen = (other.position - transform.position).sqrMagnitude*200;
            print (sqrLen);
    }else if ( sqrLen > closeDistance*closeDistance ){
        sqrLen = (10000);
        print("Max reached");
    
    }
    
    

    }

  • A look at script (for the cube to look at the ball)

    var target : Transform;

    function Update() {

    transform.LookAt(target);
    
    

    }

  • a kick script (when I release the mouse he goes to the ball and hits it)

    function OnMouseUp () {

    rigidbody.AddForce(transform.forward *Magnitude.sqrLen);
    
    }
    
    
  • Configurable joint (to stop the cube from moving(z) or rotating(x))

  • On collision script to make it go back to its starting position after he hits the ball

Ball

  • Rigidbody
  • Configurable joint (to stop the cube from moving(z) or rotating(x,y))

Now all is kinda working ok, except that it passes through the ball allot of times, not always. It works if he's speed is not to high but when I drag my cube further away from the ball to make it kick the ball harder it goes through it. I know it is hitting the ball because after he passes through the ball he returns to he's starting position (the On Collision script on the cube).

I hope I made it clear what my intentions are and what is going wrong. :)

I am rather new to Unity3d so I don't know if what I am doing is the right thing to do.

Any help is very welcome.

Aaron

Havn't got time to read everything, but try this script :)

link text