Hello there, im trying to make a game where my camera is similar to the Tales of Berseria. On Tales the camera goes around the player on the X and Y axis (the Y axis has a limit), it has a zoom in and out (with limit) and the camera can collide with walls, bringing it closer to the player (and when it stops colliding, she goes to her normal position)
I am a noob at unity and this is how far i could get:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraSeguir : MonoBehaviour{
public float turnSpeed = 4.0f;
public Transform player;
public RaycastHit hitpoint = new RaycastHit ();
public float smoothing = 5f;
private Vector3 offset;
void Start () {
offset = new Vector3(player.position.x, player.position.y, player.position.z);
GetComponent ().fieldOfView = 20f;
}
void Update () {
if (Input.GetAxis (“Mouse ScrollWheel”) > 0)
{
GetComponent ().fieldOfView–;
}
if (Input.GetAxis (“Mouse ScrollWheel”) < 0)
{
GetComponent ().fieldOfView++;
}
}
void FixedUpdate() {
Vector3 TargeCamPos = player.position + offset;
transform.position = Vector3.Lerp(transform.position, TargeCamPos, smoothing * Time.deltaTime);
if (Physics.Linecast (transform.position, player.position, out hitpoint))
Debug.DrawLine (transform.position, player.position);
}
void LateUpdate()
{
offset = Quaternion.AngleAxis (Input.GetAxis(“Mouse X”) * turnSpeed, Vector3.up) * offset;
transform.position = player.position + offset;
transform.LookAt(player.position);
}
}
My camera rotates on the X axis, follows the player and has an zoom in and out. What i want to now know is how to make it rotate on the Y axis aswell (with limit), put a limit on the zoom in and out and how to use my raycasthit to bring the camera closer when it hits a wall and to return it when there is no collsion.
Sorry for my bad english, i already tried to see the documentation and some tutorials on youtube but i cant get it done… If you guys give me any advice or tell me what code to use, I thank you.