Unity racing game tutorial lap




















Can anyone tell me how I can attach these two scripts to the Unity car tutorial please? This is one way to skin the cat, or crack the nut if you will: First of all we need an object that will trigger the checkpoint areas, a player for instance. AddForce Input. Find "Sphere Player ".

GetComponent player. Although for more robust AI you would want to look at implementing UnitySteer. If you are using C Language. Then here is the C version of CheckPoint and Laps system. Laps Script using UnityEngine; using System. Your answer. Hint: You can notify a user about this post by typing username. Then we setup a scrollSpeed and add a xAxis boolean. This is so we can control which direction we will scroll in. In the start method we will get our renderer component and assign it to rend.

Then finally in our update method we will calculate our offset which takes our time and multiplies it by our scroll speed. Then we do a check for which axis we are scrolling on and apply a texture shift on that axis. I have set the scrolling speed to 1 to give it a reasonable scrolling speed. If you have done everything right you should end up with this.

Lets add scrolling clouds. So again add a new quad to your scene. Call it Clouds. Then go ahead and drag and drop your clouds. If yours does not look like this you may need to adjust your clouds material. Head over to the materials folder. Go back up one folder and select your clouds and make sure you have repeat select and click apply.

Then simply drag the ScrollingBackground script onto the quad and check the xAxis check box. Use the settings I used below. First thing we want to do is just bring our car into our scene. So go over to the car. To do this click on the car object in your hierarchy. Once that is done we want to assign them so click on your car again and change your sorting layer to this.

To get started on our script you need to add a Rigidbody2D to your car. To do this click on your car in the hierarchy. Next we need to make sure our rigidbody2d is a kinematic body. So on the right make sure your settings look like this. Great now we can create our car controller script. To do this go into your scripts folder and right click and create a c script called PlayerController.

Open up the cs file and drop this in there. So here is how the script works. First we declare a rigidbody2d as rb. Then we declare movespeed and direction. These will control the direction and speed we moving in. In the start method we initialize our rigidbody2d component. Then finally we apply velocity on the x axis using the fixedTime, moveSpeed and direction from our input. If all was done correctly you should now be able to hit play and end up with this.

If you press the right and left arrow keys you should be able to move the car around. In order to create a menu for our game we need to first create a new scene. So go to file then click on new scene. To do this first we want to bring in a canvas. I would be interested to see a solution that does not encounter this problem. Assuming that the track is a 3d object and he has vertices along the outside and inside edges, then he can get the lengths of the inside and outside edges along those vertices.

Adding them together and dividing by two would give the length through the center of the track. What I'd probably do would be to define the track with some loop line. I'd calculate the position on the line by looking for the closest point of the car to the line. Here you'd also need some way how to prevent discontinuities when your car goes off the track and closer to some other part of the loop, by somehow "dragging" the control point over the line, like it was a rail.

Attachments: Up to 2 attachments including images can be used with a maximum of To help users navigate the site we have posted a site navigation guide. Make sure to check out our Knowledge Base for commonly asked Unity questions. Answers Answers and Comments. How do I make laps in a racing game? Magnetic Race Track? How to stick to a tubular track? Leave a Reply Cancel reply Enter your comment here Fill in your details below or click an icon to log in:.

Email required Address never made public. Name required. History of Gran Turismo. Creating LODs for Unity. Create your website with WordPress.



0コメント

  • 1000 / 1000