The Car Tutorial Part 2 Creating a Racing Game for Unity

Similar documents
Roehrig Engineering, Inc.

SHOCK DYNAMOMETER: WHERE THE GRAPHS COME FROM

APPENDIX A: Background Information to help you design your car:

RZR 900 spring/shock installation

The Mark Ortiz Automotive

How to Build with the Mindstorm Kit

Chapter 7: DC Motors and Transmissions. 7.1: Basic Definitions and Concepts

THE HAIRPIN: Talking about sliding sideways,

Initial release.

Part 1. The three levels to understanding how to achieve maximize traction.

Chapter 12. Formula EV3: a racing robot

Some tips and tricks I learned from getting clutch out of vehicle Skoda Octavia year 2000

4.2 Friction. Some causes of friction

Setup Guide and Chassis Tuning Tips (simple version) By Jim Daniels

Escaping the Kill Zone (Ramming)

Self-Concept. The total picture a person has of him/herself. It is a combination of:

Compression Tuning System

Connecting the rear fog light on the A4 Jetta, while keeping the 5 Light Mod

How I installed new brake pads on my i with Sport Package (should be fine for other E39 s) By Robert B.

SV SHOCK ABSORBERS. Few things you should know about the SV Shock absorbers

Multirotor UAV propeller development using Mecaflux Heliciel

Cane Creek Double Barrel Instructions

2 Dynamics Track User s Guide: 06/10/2014

Tutorial. Running a Simulation If you opened one of the example files, you can be pretty sure it will run correctly out-of-the-box.

Rebuilding the Power Steering Pump for a 2007 Honda Accord 4CYL

The Life of a Lifter, Part 2

Fly Rocket Fly: Design Lab Report. The J Crispy and The Airbus A

BOBSLED RACERS. DESIGN CHALLENGE Build a miniature bobsled that can win a race down a slope.

PRESEASON CHASSIS SETUP TIPS

Sunroof Repair. Sunroof Repair TSB. The sunroof repair kit available for the J30 is part number Y20. See images at bottom of document.

VEHICLE TOWING SAFETY

Winterizing the Truma-Equipped Winnebago Travato

Shock manual V3.1 ENGLISH

Lifting Mechanisms. Example 1: Two Stage Lift

An Actual Driving Lesson. Learning to drive a manual car

2001 V70 T5 ETM Removal and Cleaning Directions

Troubleshooting Guide for Limoss Systems

Wench With a Wrench. By Gail Wagner. A Shocking Discussion. Should I or Shouldn t I? That is The Question

Introduction: Problem statement

Between the Road and the Load Calculate True Capacity Before Buying Your Next Trailer 50 Tons in the Making

AMT Motorsport C7 Corvette Camber Kit User s Guide. 8 Upper Control Arm Studs and hardware for rear upper control arm adjustments

SIZING POWER SYSTEMS FOR ELECTRIC AIRPLANES

Robot Preparation for the VEX World Championship/ US Open. Lessons learned over the past 6 years by David Kelly 2013 VWC, Teacher of the Year

2006 RockShox Pike 454 Air U-turn

ROBOTICS BUILDING BLOCKS

Disco 3 Clock Spring / Rotary Coupler replacement

Spring manual V3.1 ENGLISH

Test of. Bell UH-1Y Venom. Produced by Area-51 Simulations

Speakers and Motors. Three feet of magnet wire to make a coil (you can reuse any of the coils you made in the last lesson if you wish)

Replacing MK4 Golf/Jetta radiator mounts in-car

Eibach Pro-System-Plus

How to Change Front Brake Pads on a Toyota Corolla

TAYO EPISODE #22. SPEEDING IS DANGEROUS. TAYO (VO) Speeding is Dangerous! Hm-hm-hm hm-hm-hm... NA Tayo is driving along the river on his day off.

Actual CFM = VE Theoretical CFM

The man with the toughest job in F1

4TH GEN SEATS IN A 3RD GEN TRUCK

Potentiometer Replacement

Trading the Line. How to Use Trendlines to Spot Reversals and Ride Trends. ebook

GR40 SLA Installation and Set Up Instructions.

Deriving Consistency from LEGOs

Welcome! mhtml:file://c:\newgti\technical Resources\SmartCamber Manual.mht

Jet Aircraft Propulsion Prof. Bhaskar Roy Prof. A.M. Pradeep Department of Aerospace Engineering Indian Institute of Technology, Bombay

Stopping distance = thinking distance + braking distance.

Everything You Need to Know About. Aerodynamics. By Julien Versailles

Thanks for Ordering The Kawasaki KLX Adjustable Lowering Kit From

Supervisor: Johan Abrahamsson Author: Tomas Löfwall. Measuring Acceleration in Vehicles using the AccBox System Results and Discussion

This is what we are trying to create in the steps below

Hood stripes Tools needed from AutoZone or any auto parts store: bottle spray, squeegee, a towel that you re using to clean you car up after washing,

Safe Braking on the School Bus Advanced BrakingTechniques and Practices. Reference Guide and Test by Video Communications

Car. 1/4 Lane guide Track 1-5/8. Figure 1. Car and lane guides.

BeetleBot. The Simple Zippy Screw-Together Robot Kit! SKU: K JB. jb/

Chapter 12 Vehicle Movement

Eurocompulsion Camshaft Installation

Troubleshooting Guide for Okin Systems

Triumph Street Triple VSM Grip Heater Install

If you ve had the pleasure of rebuilding

Chapter 6: Small scale solar electricity

Understanding, Repairing and Troubleshooting 3-Way Circuits and Switches

Friction and Momentum

How to Set the Alignment on Ford Mustangs

WARNING These following pages are instruction for C5 CE stripes; however, it is the same method applying vinyl. Please spend time to read thru these

Tech Tip: Trackside Tire Data

RAMPAGE POWER LIFT RAMP

X4-X7 Hyper 600cc Chassis Setup Guide

I want to try my hand here at doing a TacoBill write up so here it goes.

HOW TO USE A MULTIMETER, PART 4: MEASURING CURRENT (AMPERAGE)

Users are provided with the same installation file for both Workstation and Render node MadCard_WS.exe

An Actual Driving Lesson Learning to drive an automatic car

How to Keep your Treadmill Running

Fig 1 An illustration of a spring damper unit with a bell crank.

S1 Sequential. T56 Magnum. Sequential shifter. Contents and assembly instructions

Fitting the Bell Auto Services (B-A-S) TDV6 EGR Blanking Kit to a 2006 model Discovery 3 TDV6 HSE

Door panel removal F07 5 GT

HOW T O TO B UILD BUILD A F AST F PINEWOOD DERBY C AR CAR Scotten W. Jones

*Some speedometers have these additional electronic connections. If yours does, then remove the smaller slotted screws shown.

Solar Power. Questions Answered. Richard A Stubbs. Richard A Stubbs 2003, distribution permitted see text for details

The Panic Slip. Let the Racing Begin!!! Results for our events are available on our web site at

Wine Glass Orchestra. Leah Buechley CSCI 7000 Things That Think

4.4. Forces Applied to Automotive Technology. The Physics of Car Tires

The Holly Buddy. 2.5cc Model Diesel - Compression Ignition engine.

Transcription:

The Car Tutorial Part 2 Creating a Racing Game for Unity

Part 2: Tweaking the Car 3 Center of Mass 3 Suspension 5 Suspension range 6 Suspension damper 6 Drag Multiplier 6 Speed, turning and gears 8 Exporting the car as a package 9 Suspension spring 6

Part 2: Tweaking the Car If you ve followed along part 1 of this tutorial and assembled the car, you are already at a point where the car is pretty awesome. But if you have driven it around a bit, you will probably have noticed that there is after all room for some improvement. This is where tweaking enters the picture. In game development tweaking is a crucial part of making your game fun, challenging, awesome or whatever goal you have for your specific game. The idea is that when you have setup the nuts and bolts that makes your game run, there might be something that doesn t feel quite right - maybe you want the car handling to be a bit different, maybe you want the top speed to be slightly different, or maybe you want to change the scene lights. A major strength of Unity is it s tweakability - as you have seen, all the public variables in your scripts are shown in the inspector, so you can change values without going into the code. And even more powerful: When you ve made a change you just hit play, and you will instantly see the result of that change. You never have to wait for the scene to be rebuilt or for a major recompile of the code. Center of Mass Now the most obvious thing that needs to be tweaked is probably that the car can very easily be flipped around when turning (if you haven t tried yet, then play again and speed up a bit and then turn from side to side while speeding - the car will will flip over pretty easily). The reason for this flipping is that we haven t yet defined the car s center of mass. All the forces that are applied to the Rigidbody of the car, are all applied at the Rigidbody s center of mass. The center of mass of the Rigidbody will be calculated by Unity according to the Colliders attached to the Rigidbody, either on the same GameObject or on child objects. Since the center of mass of a car is typically not 3

the center of the car (and probably not the center of mass that Unity calculates), we want to set the center of mass ourselves. The position of the center of mass for a car depends on the placement of the engine and other factors, and it can vary a lot from one car model to another. For the car in this tutorial project the center of mass could be a little behind the engine, slightly above floor height of the car. See it s position in this image: Create a new GameObject and drag it to the Car game object. Rename it to CenterOfMass Reset the CenterOfMass s Transform (click the little cog wheel to the right of the Transform in the Inspector and select Reset. This will give it the same position as its parent, the car. Adjust its position to somewhere you like. Either do it by dragging, or type in the position. A good position for this car s center of mass could be (0, 0.1, 0.65). In the Inspector assign the CenterOfMass to the slot for it in the Car script Component. In general, it is a bad idea to have the center of mass be positioned to either side of the center in the x-axis, because this will make the steering behave oddly, and thus we have also set the x variable of the position to 0. You can also change the Camera s target to be the CenterOfMass Game Object instead of the car 4

itself. This will give a slightly different feeling - play around with it and decide which setting you like the most. Suspension Another factor that can heavily change the behavior of the car is the properties of its suspension. The job of a car suspension is to maximize the friction between the tires and the road surface. When you are driving the car over a bump, all of the wheel s vertical energy gets transfered to the frame. If we did not have an intervening structure, this could easily result in the wheel loosing contact with the road completely, and afterwards slamming down into the road because of the force of gravity. The suspension is that intervening structure. We have three different variables to tweak from the Inspector - the range, the damper and the spring. All are part of the WheelCollider class that we use on the car s wheels. To the left we see the car with the standard settings, and to the right we see it with a much larger suspension range. Combined with the spring and damper properties, you can make it behave like everything from a formula one car to a huge monster truck. Of course the graphics need to match the settings to make it believable though! 5

Suspension range This is the length of the suspension from when it is a state of being fully compressed to the largest distance it can be away from the frame of the car. Suspension spring The value set here determines the stiffness of the suspension spring. Setting it very high makes it more likely that the suspension will be fully extended, so that the wheels will be far away from the frame, and setting it very low will make the suspension much more bouncy. When tweaking this value, it will be clear that the mass of the car also has a lot to say here. A very heavy car requires a spring with more stiffness than a very light car. By default we have set the rear suspension spring to be less stiff than the front and the reason is that the center of mass is distributed more to the front side, requiring better suspension there. Playing around with different values for both front and rear suspension can yield very different results. Suspension damper Dampening helps controlling the motion in the suspension. Without dampening, the suspension spring would extend and release it s energy at an uncontrollable rate - it would extend at it s natural spring frequency until all the energy stored in it was used up. This would result in an extremely bouncy and uncontrollable car. The damper or shock controller turns the unwanted kinetic energy into heat that gets transferred away in the hydraulic fluid, making the ride a lot smoother. Drag Multiplier When we added the Rigidbody to the car, we saw that it had a drag property. This drag is the 6

intertia or air resistance that affects the Rigidbody, making it harder to move. When a car is designed, a lot of consideration is often put into giving it a shape that minimizes the friction from the air resistance when it moves. But since a car is meant to move forwards, the shape takes this into account - just take a look at the car model in the editor from the front, the sides and the top, and you will realize that it is a lot more streamlined when seen from the front than from sides and top. We take this into account by creating our own drag multiplier property that we use instead of the drag property built into the rigidbody. Take a look at the Car script component in the Inspector, where you will see that we have a Drag Multiplier variable, which is a vector with x, y and z values. This makes it possible for us to set different drag values for the front, sides and top of the car, mimicking the real conditions when driving a car more accurately. The X value is the drag to the side The Y value is the drag to the top The Z value is the drag to the front The x value is important in controlling the force that prevents the car from sliding sideways when turning. The higher the x value the more sideways resistance. The z value is by far the most interesting one because it can lower or increase the force that slows the car s velocity down. If you set it to less than 1 you will get less resistance, faster acceleration and a higher top speed. More than 1 and the car must struggle against a more powerful force in order to move forwards, making it slower. The drag values are very sensitive, so you are advised to experiment with small changes when tweaking the drag. 7

Since the car is not supposed to travel upwards, the y value is not as interesting to change. The most important force controlling the car in the y-axis is after all the gravity that affects the rigidbody. Speed, turning and gears Now we ve gotten to the more obvious variables that also has a quite large impact on your cars behavior. The Top Speed variable is a no-brainer: This sets how fast (or slow) your car can go. Since our car model is a lot simpler than a model for a real car, and we for example don t really have any values to set that affects it s acceleration (except the drag), the Top Speed variable will also indirectly affect the acceleration. Making the car very fast will also make it reach a high velocity equally higher and vise versa. If you want to play with top speed and acceleration, you could try tweaking both the Top Speed value and the drag s z variable (which was the air resistance in the forward direction) For turning we have two variables - Maximum Turn and Minimum Turn. Both are values for how good the car is at turning. A high value means excellent turning and a low value is very limited turning ability. We are using them together in the car s script to change the cars ability to turn based on how fast it is going: At very low speeds, it is the value set for Maximum Turn that is used when turning. The higher the car s speed gets, the closer it s turning ability gets to the Minimum Turn. What this adds up to when using the default values for the Car (which are 10 for minimum and 15 8

for maximum) is that it gets harder to turn when you go fast. This gives a more realistic feel, ensuring that you can t just go at full speed into a hairpin bend and expect the car to survive it. You can experiment with both values to make the car better or worse at turning and for making the difference between turning when going slow and fast higher or lower. Finally we have exposed the Number Of Gears variable. When we get to the part where we look inside the Car script we will see what this is used for calculating. Since the car is based on a simple model, the gears are not mimicking real gear behavior. However, they are used to calculate the engine forces, and maybe more importantly they are used in the script controlling the sound, to change the sound of the engine s pitch, based on what gear we are currently in, and how fast we are currently going. This makes the car sound like it is starting at low RPM in each gear, and increasing the RPM until it reaches the limit, where it will switch the gear. Setting this value to another number of gears simply creates an illusion through sound of how many gears the car has. Exporting the car as a package If you have followed along and assembled your own version of the car, you now have the knowledge needed to implement it in your own projects. An easy way to transfer it across projects is to make a Unity Package from the needed Prefabs. First lets turn the car we made into a Prefab so it can be reused without doing the assembling and tweaking: In the Project view click Create and select Prefab. You will get an empty Prefab in the project view named new prefab. 9

Rename the Prefab to Race Car (a nice palindrome) or any other name to your liking. Drag the Car GameObject from the Hierarchy view and onto the Prefab. This has already been done for you though (it is in Prefabs/Car), but now you also have your own. There are a few parts that are needed apart from the Car Prefab in order to create a package that just works from scratch. These are the Skidmarks, Main_Camera and Directional_Light_Car_Road. Fortunately they have been made into Prefabs already. There are also a few scripts that we need to include in our package, which won t get included if we don t specify it: SoundToggler.js, ImageEffects.cs and ImageEffectsBase.cs The reason is that these scripts are not included in the scene, but used through scripting when the game runs. The image scripts are included in the Pro Standard Assets, but we are including them in the package so it can be imported into a completely empty project and just work. In the Project view select all of these items: Prefabs/VFX: Directional_Light_Car_Road, Main_Camera, Skidmarks scripts/javascripts: SoundToggler.js Pro Standard Assets/Image Based/ ImageEffects.cs and ImageEffectsBase.cs 10

The Car Prefab that you created. Click Export package... In the pop-up make sure that Include dependencies is checked. This will gather all Assets that your selection depends on with the exception of assets that are only accessed through scripting. Click Export, choose a name for your package and save it. The process of getting your Car into your own project is now simple: In your new project go to Assets->Import package... Navigate to the package you saved and open it. Make sure that everything is selected (Click All ) and then click import. Unity will import all the Assets and the prefabs will appear in your Project view, ready to be dragged into a scene. You are totally free to take the car and use it in your own projects, and now you have the knowledge to put it together, tweak it and transfer it across projects - so please go ahead and make a really awesome driving game! 11