Car Physics
-intermediate-
-intermediate-
Import sprites to your Unity Project. Use the track file you made yesterday. There are car body, wheel, and passenger sprites available in the shared drive W:\HS\Osowski, Z\Video Game Design\Car Game. Be sure to set your filter mode for all sprites to "Point".
Create a new 2D sprite object in your hierarchy as a child of the main camera. Attach your car body sprite to this object and name it "Car". The car body object will also need a polygon 2d collider and a rigidbody2d component so it can collide with other objects in the scene.
Create a 2D sprite object in your hierarchy for each of your wheels. The wheel objects need to be parented to the car body (picture). They also need rigidbody2d and circle collider 2d.
Add two "Wheel Joint 2D" components to your Car GameObject. Change the "Anchor" points on each wheel to the location you want them attached to the car. Attach each wheel to the Wheel Joint 2D components under the field "Connected Rigidbody".
Create a new 2D Sprite GameObject in your hierarchy named "Track". Attach your track sprite to this object, then give it a Polygon 2D Collider component.
Add a new C# script as a new component to your Car GameObject. Write this script. When done, be sure to attach your back and front wheels to your Car Controller script in the inspector.
Create a physics material for the track and for the wheels. Attach these physics materials to the wheels and track. Without these physics materials, the wheels will slide and slide on the track.
Create a camera controller script for your camera that allows it to follow the car around.