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?
3 Answers
3I 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
– LittleJohnGamesWhen 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!
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.
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. More 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.
– KitCoo