- Home /
Simple 2D Car Game
I only started basic coding last Sept. For college, we have to make a 2D game of our choice. I chose to make a car game, but I having trouble with the script and making the car move forward. I have been searching online for the past 2 hours trying to find car tutorials, but I couldn't find any ones with script, and when I did, I had to pay for them (being a student I don't really have money). Are there any simple tutorials around to help me out? Or can anyone give me any help at all?
I am Pretty new to Unity as well I would imagine that to do 2d car would be as simple as just a sprit character as well. Personally I have not specifically looked for 2d car tutorials, but I think the best place for you to begin would be the Unity Tutorials they offer great info and never cost money. $$anonymous$$ore important is that it is good information. So check out the 2d tutorials and build a 2d character controller and if I am not mistaken just a sprite should work with some inventive colliders. Just a thought but again I am pretty new myself. Hope that helps and does not hinder.
ok so some testing and I have used the 2d wheel collider. I put box gave it a rigid 2d. $$anonymous$$ade to wheels with the joystick sprites. Gave them rigid 2d as well. now I gave both wheels 2d wheel joint. Ok now I had success when I did not parent the wheels to the box. Another thing to note is that the Wheel joint is a joint not suspension. Now put the rigid 2d into where the wheel joints ask and here you have a platform on wheels. add force to the motor and it rolls. After that if you want to control your car you will have to build a simple motor script and attach it to the box. Again Am Still $$anonymous$$ind of noob myself. But have had success in what I need the wheel joint for just platform on wheels I add motor power to make it move for platform obstacle. Hope this with the tutorials will get you on your way good luck friend.
Answer by LittleJohnGames · Apr 26, 2015 at 07:09 PM
I have changed the script to set up EVERYTHING. Just drag and drop onto your car sprite and it will work. HERE IT IS
@script RequireComponent(Rigidbody2D)
var Speed : float = 5;
var RotationSpeed : float = 3;
function Awake(){
GetComponent.<Rigidbody2D>().angularDrag = 1;
GetComponent.<Rigidbody2D>().drag = 1;
GetComponent.<Rigidbody2D>().mass = 1;
GetComponent.<Rigidbody2D>().gravityScale = 0;
}
function FixedUpdate() {
var ZRotation : int = Input.GetAxis("Horizontal") * RotationSpeed;
var YSpeed : int = Input.GetAxis("Vertical") * Speed;
GetComponent.<Rigidbody2D>().AddTorque(-ZRotation, 0);
GetComponent.<Rigidbody2D>().AddForce(transform.up * YSpeed);
}
This is once again Javascript so remember to put it in a JS file. It handles all of the basic player controls for a 2D car game, so should be enough to get a car moving. As for other elements, I am not too sure either. Looking at a basic 2D game tutorial should be enough to start up the game.
I edited the script to use a 2D rigidbody and set up everything required, but do not have it as it is on my PC. I'll try and get it up here
Answer by DavidZendle · Apr 24, 2015 at 10:44 PM
When it comes to car tutorials, there's always the old Unity Studios one
I remember making a racing game a while ago, and I found it pretty helpful - of course, though, it's 3D, so your mileage may vary.
However, for 2D car tutorials, I'm at a loss. You could always start out with a general overview and work your way up? Having a good grasp of the basics always helps in the long term!
Answer by gpaulguilfoyle · Jan 14, 2020 at 06:48 PM
Here is an awesome tutorial on how to make a unity 2d racing game. The tutorial covers unity ads as well for monetizing a truly begin to finish unity racing game tutorial.
Your answer
Follow this Question
Related Questions
how to make 2D physics-based car / motorcycle game? 2 Answers
Movement based on rotation 1 Answer
Attempting to add wheel friction to a 2d car 1 Answer
Saying the car is riding wrong way 0 Answers
Making a race car positioning system 5 Answers