Hello i watched the tutorial how to make roll a ball camera that is like i want but not rly. I want it to be able to zoom in and zoom out with scroll wheel and rotate camera around the ball with a and d a is left d is right. How can i do that? please i need help.
Here is the code:
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
public GameObject player;
public float moveSpeed = 10f;
private Vector3 offset;
void Start ()
{
offset = transform.position - player.transform.position;
}
void LateUpdate ()
{
transform.position = player.transform.position + offset;
//if(Input.GetAxis ("Mouse ScrollWheel") > 0f ){
// transform.Translate (Vector3.forward * moveSpeed * Time.deltaTime);
//}
}
}
I will still try to fix this problem my self but i cant seem to find a way to do this. Thanks.
I fixed it but it was hard. I made a custom ball anchor that does not change.
BallAnchor:
using UnityEngine;
using System.Collections;
public class BallAnchor : MonoBehaviour {
public GameObject ball1;
private Vector3 offset;
// Use this for initialization
void Start () {
offset = transform.position - ball1.transform.position;
}
// Update is called once per frame
void LateUpdate () {
transform.position = ball1.transform.position + offset;
}
}
And then this is the camera component:
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
public GameObject ball1 = null;
//public float moveSpeed = 10f;
//private Vector3 offset;
void Start ()
{
}
void Update ()
{
if (ball1 != null) {
transform.LookAt (ball1.transform);
//if (Input.GetAxis ("Mouse ScrollWheel") > 0f) {
// transform.RotateAround (ball1.transform.position, new Vector3(0, 1, 0), Time.deltaTime * 150);
//}
}
}
}
Camera GameObject is set to the custom ball anchor and the camera is custom ball anchor child.