I am attempting to make a 2D racing game. So far I have a player car (sprite) and a main camera.
I would like to know how to make the main camera follow the player car while still showing signs of movement (I don't want the positions to match exactly in the middle of the screen).
My Player Car has a Rigidbody2D
and a MoveCar
script
using UnityEngine;
using System.Collections;
public class MoveCar : MonoBehaviour {
public float speed = 10f;
public float gravity = 0f;
void CarMove ()
{
if(Input.GetKey(KeyCode.RightArrow))
{
transform.Translate(Vector2.right * speed * Time.deltaTime);
}
}
// Update is called once per frame
void Update ()
{
CarMove();
}
}
Then there is my Main Camera, its projection is switched to Orthographic and has default settings as well as a FollowCar
script:
using UnityEngine;
using System.Collections;
public class FollowCar : MonoBehaviour {
public Transform player;
public GameObject other;
public Rigidbody2D rb = other.GetComponent<Rigidbody2D>;
void Update()
{
transform.Translate(Vector2.right * .5f * Time.deltaTime);
Vector2.MoveTowards( Vector2 , Vector2 player,
}
}
I would like to know where to go next or if I'm even going in the right direction. I have no idea how to utilize the MoveTowards() function.