- Home /
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))
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
Answer by EpikOwnage · May 10, 2010 at 06:34 PM
Havn't got time to read everything, but try this script :)
Hi Epic,
wow that was fast! :) Thanks for pointing me to that script. I tried it and it already works allot better, sadly not perfect. It always hits the ball now but sometimes it stops in front of it and hangs there :)
Aaron
Your answer
Follow this Question
Related Questions
How to make player (sphere) shoot the ball (another sphere)? 2 Answers
Collision problem 0 Answers
How do I instantiate and shoot a ball along a ray cast? [ANSWERED] 1 Answer
Moving a group of objects at once in runtime. 1 Answer
How to predict where the ball will land after being hit by bat? 4 Answers