mirror of
https://github.com/ConjureETS/OuijaMTLGJ2016.git
synced 2026-03-24 02:01:06 +00:00
add lookAt offset to camera for more control
This commit is contained in:
parent
c90d913cf4
commit
75a825c62d
@ -4,19 +4,12 @@ using System.Collections;
|
|||||||
public class MainCameraBehavior : MonoBehaviour {
|
public class MainCameraBehavior : MonoBehaviour {
|
||||||
|
|
||||||
public Transform targetTransform;
|
public Transform targetTransform;
|
||||||
public float y = 2.5f; // store the height value since it will never change
|
|
||||||
public float offsetZ = -2.2f;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public float smooth = 1.5f; // The relative speed at which the camera will catch up.
|
public float smooth = 1.5f; // The relative speed at which the camera will catch up.
|
||||||
|
|
||||||
|
public float screenCenterOffsetX = 0f;
|
||||||
|
public float screenCenterOffsetY = 0f;
|
||||||
|
|
||||||
private Vector3 relCameraPos; // The relative position of the camera from the targetTransform.
|
private Vector3 relCameraPos; // The relative position of the camera from the targetTransform.
|
||||||
private float relCameraPosMag; // The distance of the camera from the targetTransform.
|
private float relCameraPosMag; // The distance of the camera from the targetTransform.
|
||||||
private Vector3 newPos; // The position the camera is trying to reach.
|
private Vector3 newPos; // The position the camera is trying to reach.
|
||||||
@ -94,6 +87,10 @@ public class MainCameraBehavior : MonoBehaviour {
|
|||||||
// Create a rotation based on the relative position of the targetTransform being the forward vector.
|
// Create a rotation based on the relative position of the targetTransform being the forward vector.
|
||||||
Quaternion lookAtRotation = Quaternion.LookRotation(reltargetTransformPosition, Vector3.up);
|
Quaternion lookAtRotation = Quaternion.LookRotation(reltargetTransformPosition, Vector3.up);
|
||||||
|
|
||||||
|
// give an offset to look at centering
|
||||||
|
lookAtRotation.x += screenCenterOffsetY;
|
||||||
|
lookAtRotation.y += screenCenterOffsetX;
|
||||||
|
|
||||||
// Lerp the camera's rotation between it's current rotation and the rotation that looks at the targetTransform.
|
// Lerp the camera's rotation between it's current rotation and the rotation that looks at the targetTransform.
|
||||||
transform.rotation = Quaternion.Lerp(transform.rotation, lookAtRotation, smooth * Time.deltaTime);
|
transform.rotation = Quaternion.Lerp(transform.rotation, lookAtRotation, smooth * Time.deltaTime);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user