Full Camera System
I just about have my camera controller working like a true MMO system. But I been having issues as I am note a coder
What I want it to do:
Have Switch view options
Zoom with scroll wheel and right mouse BTN to rotate views.
Smoothly Follow player.
Not utilizing the Main Camera.
Not effecting player movement, but rather the reverse.
To be made available with a tutorial setup as a free asset for others who have the same issues with coding that i have.
Eventually include it in with another clean and full function player controller setup that again does not rely on main camera, cross platform inputs as with the usual standard assets scripts, and more or less more easily customized and utilized for end users as a free asset.
Why?
To be frank about it, most of the standard assets camera systems and player controllers are designed more or less as demos and often are buggy which is not something most non-coders can resolve. So my intention is to create or have help creating a combination camera (single script page) and player controller (also single script page with all the basic physics working properly) system so people can get started right away with it.
Side Note on Switch View:
1) I have to use Alpha 1 and 2 in order to change the switch views (because i chose them on purpose). However, i was trying to originally set these view changes to smoothly shift from one to the other. The coding i did originally just would not allow it so its a rapid switch (for now).
The problems are:
When switching views the camera does not stay facing the direction of the player when moving.
Even when using the smooth follow option, the camera setup drags along causing a jerking effect.
Only the third person camera have zoom in and out options (coding the same options for the other two threw back errors i cannot fix).
Smooth follow does not work.
Camera do not return to default forward look position automatically as needed.
I do not want player movement influenced by where the cameras are facing. I want it the reverse where the cameras are influenced by the direction the player is facing. (I.E. if i am moving forward, backward or turning, i want the cameras remain facing in their default positions as though i had simply made them children of the player parent prefab).
I cannot seem to add any more coding such as preventing clipping of cameras. I was trying to set it up to also include this feature so they would not pass through or see through mesh objects like walls. (Note: simply adding a collider on a camera does not work properly as has been suggested to me before).
What i have listed the cameras as:
FP & First P Camera for first person.
TP & Third P Camera for third person.
Second Person as a looking back at player camera.
(I understand some may complain i posted this much information. However, these details I posted above are necessary so i can clarify needs and issues with this specific feature so what i need is made clear from the start and any further explanation not needed).
My present coding setup.
using UnityEngine;
public class CameraControls : MonoBehaviour
{
[SerializeField]
Camera firstPCamera;
[SerializeField]
Camera thirdPCamera;
[SerializeField]
Camera secondPCamera;
private bool switchCam = false;
private bool backCam = false;
public Transform thirdPCam, firstPCam, secondPCam, player, centerPoint;
private float cameraSpeed = 1000;
public float zOffset = 0;
public bool smoothFollow;
private float mouseX, mouseY;
private float moveFB, moveLR;
private float zoom;
public float zoomSpeed = 2;
public float zoomMin = 0f;
public float zoomMax = -10f;
// Use this for initialization
void Start()
{
firstPCamera.GetComponent<Camera>().enabled = true;
thirdPCamera.GetComponent<Camera>().enabled = true;
secondPCamera.GetComponent<Camera>().enabled = true;
zoom = 0;
}
// Update is called once per frame
void Update()
{
if (player)
{
Vector3 newPos = transform.position;
newPos.x = player.position.x;
newPos.z = player.position.z - zOffset;
mouseY = Mathf.Clamp(mouseY, -60f, 70f);
centerPoint.localRotation = Quaternion.Euler(mouseY, mouseX, 0);
if (smoothFollow) transform.position = newPos;
else transform.position = Vector3.Lerp(transform.position, newPos, cameraSpeed);
}
zoom += Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
if (zoom > zoomMin)
zoom = zoomMin;
if (zoom < zoomMax)
zoom = zoomMax;
thirdPCam.transform.localPosition = new Vector3(0, 0, zoom);
if (Input.GetMouseButton(1))
{
mouseX += Input.GetAxis("Mouse X");
mouseY -= Input.GetAxis("Mouse Y");
}
if (Input.GetKey(KeyCode.Alpha1))
{
switchCam = !switchCam;
backCam = false;
}
if (Input.GetKey(KeyCode.Alpha2))
{
switchCam = !switchCam;
backCam = true;
}
if (switchCam == true)
{
firstPCamera.GetComponent<Camera>().enabled = true;
thirdPCamera.GetComponent<Camera>().enabled = false;
secondPCamera.GetComponent<Camera>().enabled = false;
}
else if (backCam == true)
{
firstPCamera.GetComponent<Camera>().enabled = false;
thirdPCamera.GetComponent<Camera>().enabled = false;
secondPCamera.GetComponent<Camera>().enabled = true;
}
else
{
firstPCamera.GetComponent<Camera>().enabled = false;
thirdPCamera.GetComponent<Camera>().enabled = true;
secondPCamera.GetComponent<Camera>().enabled = false;
}
}
}
Why go to all this trouble? Because my intention is once this camera setup has been completed, it can be provided as a free asset to others as well as one I can utilize in my own 3D world project. Any assistance or simplification of coding will be appreciated.
Do note this:
If you yourself as a more experienced coder are willing to do so, please feel free to create a Tutorial video to share with me and others on this code as a Full Function MMO Camera system. Thank you very much in advance on the behalf of myself and others who I know will be looking for this specific script and its implementation.