Today we will add another biliard ball and see them colllide.
- Click on the Day 5 scene in the Project pane. All the stuff from the last lesson should appear.
- In the hierarchy pane select the sphere/ball
- Change the Sphere Collider material properties to "Rubber" in the inspector pane
- If you run this the ball plops onto the table with no bounce. That's how you'd expect a billiard ball to react - so far so good. But we need to put the ball on the table rather than drop it.
- Change the Y position of the ball to -9.4 Run and see that the ball is on the table.
- Have a play with the view settings(this is the compass type icon in the top right of the scene window) so you can view the scene from different angles i.e Top, Right, Left, Perspective etc
- We need another ball so select the sphere in the hierarchy pane and right click. The select duplicate. A new sphere will appear in the hierarchy.
- Select the new one. Right Click and rename it to "Ball2" - then move the ball to the side so the settings are x=-2, y=-9, z =4
- Run this and you will see 2 little dicky birds sat on a bird table....erm...I mean 2 billiard balls on a billiard table.
- Now we need to move one of the balls and crash it into the other! We do this with a nice script :-)
- Click the Create button in the Project pane and select "JavaScript" - a new script will appear in the project called "NewBehaviourScript"
- Open up this script and copy and paste in the following...
var oneShot : boolean = false;
function Update () {
if (! oneShot){
rigidbody.AddForce(200,0,0, ForceMode.Force);
oneShot = true;
}
}
- This adds a one time force (in the x-dirn) to a ball but first we need to assign the script to an object....
- In the project pane drag the script onto the first ball (sphere) - this associates the script with that ball.
- RUN the game and you'll see the balls colliding!
- You can now play with the masses of the balls, the force applied and direction and see if you can make the physics of the balls more billiard like!
- Another setting(s) to tweak is the bounciness of the Physic Materials in the project pane (in the Standard Assets folder).
- Also have a play with the camera settings to get a nice view of the table. You could try and make the camera projection ORTHOGRAPHIC and have it looking down onto the table from overhead. This will make it a lovely 2d game with 3d rolling textures!
Here is the final project files for the day....http://www.mediafire.com/?veola5ynbynqya4
No comments:
Post a Comment