how to find direction of two rigid bodies after collide them with each other
Basically, i want to design a cricket game where i have to decide the next moving position of a ball after hitting with bat. i m confused that whether unity can move the ball after collision itself or i have to find the new direction for the ball in script...... kindly help me if anyone can
regards: Shozii
Answer by Foulcloud · Aug 24, 2015 at 10:07 PM
Make both objects with rigidbodies and colliders. Then they will behave like real world physics and no need for coding. Rigidbodies should be set to NON-kinematic and colliders should set to NON-triggers.
the main thing about i m confused is to find the new direction of ball after collision. can the ball direction is handled by unity itself?????? thanks for your reply.....
You can move objects around in Unity in 2 ways. You can either manually control the movement or use the built in physics. In many cases you will want to use the physics in Unity to handle the behavior of your moving objects. In these cases, ins$$anonymous$$d of moving and tracking things, you simply apply forces and let Unity handle the rest. So in your case you would apply a force to swing the bat and then the physics would take over. $$anonymous$$eep in $$anonymous$$d that everything should have a rigidbody and a collider attached. Objects with non-kinematic rigidbodies will use physics to move around and bump into things. You move these around by applying forces. Objects with kinematic rigidbodies will still bump into things but will never be affected by another object. You move these around by changing the position directly. You might also set your bat as non-kinematic and move it's position directly but you still want the ball to be set to non-kinematic. That way you don't really need any code for the ball as it will simply react to other moving objects.
Your answer
Follow this Question
Related Questions
How do I keep rigidbodies from pushing each other? 2 Answers
OnMouseDown() not firing, even though attached to collider under mouse. 1 Answer
Player Movement Goes Crazy When Hit On Side Of Moving Platform 0 Answers
Why is my trigger collider acting like a normal collider? 1 Answer
How would I change material properties of a box collider via script? 0 Answers