Unity Tutorial 2
Lesson 1.4; Step into the driver's seat
(My image of the unity software with a car in one column)
Lesson 1.4 was all about finalizing the Prototype 1 project. In lesson 1.4 I learned how to move the vehicle left, and right. However, at first, it was simply drifting across the road. This was an issue because it didn't turn like a real car would be able to. So during a couple of more lessons, I was able to correct that using this code :
private float horizontalInput;
horizontalInput = Input.GetAxis("Horizontal");
transform.Rotate(Vector3.up, Time.deltaTime * turnSpeed * horizontalInput);
This allowed the car to rotate along the axis which I had seen before with testing the camera angles.
When my car was able to drift I was then able to move on to finalise my other issues.
Another issue that needed to be fixed was my vehicle speed and movement control. At first, I had my speed set to 5 from lesson 1.3, however that was a bit too slow so I bumped the speed up to 15. in order to fix movement I had to input controls for moving forward and moving backwards, which I made my w and s keys do.
Lastly in this lesson, I cleaned up my code so that I would be able to understand what each piece of code meant in relation to the game's function.
(My image of unity software with a plane)
Challenge 1; Plane Programming
Plane Programming was a set of challenges to test if I remember how my code functions. The first challenge was to make the plane go forwards as it only went backwards. I fixed this by adding the code to connect the plane to the w key to move forward from the input menu and adding the correct code to go with it.
private float forwardInput;
forwardInput = Input.GetAxis("Vertical");
transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
Next, I had to lower the number to the plane's speed as the plane was going too fast.
private float speed = 5.0f;
Next, I had to input horizontal controls as the plane was tilting by itself and after that, I had to move the camera behind the plane and fix it to behind the plane as it moved.
This was a bit of a challenge as I had to revisit my code from before and figure out what I did and didn't need for this challenge, however after one crash and restart of the challenge I eventually got it finished. Always, always, always save. If you don't save you might have ended up starting from the beginning.
Comments
Post a Comment