I tried following another tutorial using a different code as the first one didnt really work out very well.
The code is as follows:
(and is attached to my main camera)
using UnityEngine;
using System.Collections;
public class CameraMovement : MonoBehaviour {
private float speed = 2.0f;
private float zoomSpeed = 2.0f;
public float minX = -360.0f;
public float maxX = 360.0f;
public float minY = -45.0f;
public float maxY = 45.0f;
public float sensX = 100.0f;
public float sensY = 100.0f;
float rotationY = 0.0f;
float rotationX = 0.0f;
void Update () {
float scroll = Input.GetAxis("Mouse ScrollWheel");
transform.Translate(0, scroll * zoomSpeed, scroll * zoomSpeed, Space.World);
if (Input.GetKey(KeyCode.RightArrow)){
transform.position += Vector3.right * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.LeftArrow)){
transform.position += Vector3.left * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.UpArrow)){
transform.position += Vector3.forward * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.DownArrow)){
transform.position += Vector3.back * speed * Time.deltaTime;
}
if (Input.GetMouseButton (0)) {
rotationX += Input.GetAxis ("Mouse X") * sensX * Time.deltaTime;
rotationY += Input.GetAxis ("Mouse Y") * sensY * Time.deltaTime;
rotationY = Mathf.Clamp (rotationY, minY, maxY);
transform.localEulerAngles = new Vector3 (-rotationY, rotationX, 0);
}
}
}
- This code has actually worked out a lot better, it does more or less what I want it to and so may just require a bit of tweaking to get right.
- If possible, i just want the camera to follow the mouse without having to click, because i want the player to be able to click on objects in the room and interact with them as a separate action.
- Also, the camera isn't focusing on the 2D image and keeps moving away from it. This needs to be fixed. I need to see if I can look up a way to do that.
- Also, I want it to follow the mouse not rotate around one point, so as you move the mouse along the image, the camera moves with a sort of parallax effect.
- Also, I want it to follow the mouse not rotate around one point, so as you move the mouse along the image, the camera moves with a sort of parallax effect.
0 comments:
Post a Comment