Hello!
Im having some problems making the camera turn with the ball. https://youtu.be/6D337xSoQV4 in the YouTube link you can see the camera is following the ball but only show it from the same angle. I would like the camera to turn with the ball, so the backside of the ball is seen and it's possible for the player to see the road ahead.
the code for the camers:
using UnityEngine;
using System.Collections;
public class FollowBall : MonoBehaviour {
public GameObject player;
private Vector3 offset;
void Start () {
offset = transform.position;
}
void LateUpdate () {
transform.position = player.transform.position + offset;
}
}
I dont know if it's needed but i have also added the code for the ball (PlayerController):
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
private Rigidbody rb;
void Start (){
rb = GetComponent ();
}
// Update is called once per frame
void FixedUpdate () {
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement);
}
}
Hope someone have the answer! :)
↧