#Car Control with Camera Follow
1 messages · Page 1 of 1 (latest)
I'm gonna start the process in few minutes, any help is appreciated!
Alright, let's start over!
Now, we're going to start from the Camera issue, which doesn't get into its position when following the car!
followCar Script
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class followPlayer : MonoBehaviour
{
public GameObject car;
public Vector3 offset = new Vector3(16, 3, -506);
// Update is called once per frame
void LateUpdate()
{
transform.position = car.transform.position + offset;
}
}
`
The position I want the camera to closely follow!
This is when it follows the car!
This is how I want it to look like from the angle of the camera.
XYZ = (16, 3, -505)
if you want carControll Script then here it is:
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarController : MonoBehaviour
{
public GameObject car;
public GameObject rearRightTyre;
public GameObject rearLeftTyre;
public GameObject frontRightTyre;
public GameObject frontLeftTyre;
public float Speed = 150f;
public float turnSpeed = 10f;
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.W))
{
//transform.Translate(Vector3.forward * Speed * Time.deltaTime);
rearRightTyre.transform.Rotate(new Vector3(150f, 0f, 0f) * Speed * Time.deltaTime);
}
}
}`
script and instruction from this link: https://learn.unity.com/tutorial/1-3-make-the-camera-follow-the-vehicle-with-variables?uv=2020.3&pathwayId=5f7e17e1edbc2a5ec21a20af&missionId=5f71fe63edbc2a00200e9de0&projectId=5caccdfbedbc2a3cef0efe63#
Overview: Keep your eyes on the road! In this lesson you will code a new C# script for your camera, which will allow it to follow the vehicle down the road and give the player a proper view of the scene. In order to do this, you’ll have to use a very important concept in programming: variables. Project Outcome: The camera will follow the vehicl...
The code can't be any easier and don't know what's the problem!
Here I've been trying to explain!
@hollow totem @nocturne lily
I've fixed the tyre rotation using the following:
rearRightTyre.transform.Rotate(Speed, 0, 0 * Time.deltaTime);