SHADE_Y3/Assets/Scripts/Gameplay/Player/SC_ThirdPersonCamera.cs

77 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SHADE;
namespace SHADE_Scripting
{
public class ThirdPersonCamera : Script
{
public float armLength = 2.0f;
public float turnSpeedPitch = 0.3f;
public float turnSpeedYaw = 0.5f;
public bool inverseXControls = false;
public bool inverseYControls = false;
public float pitchUpperClamp = 45.0f;
public float pitchLowerClamp = 5.0f;
protected override void awake()
{
AddComponent<Transform>();
if (!GetComponent<Camera>())
{
AddComponent<Camera>();
}
if (!GetComponent<CameraArm>())
{
AddComponent<CameraArm>();
}
}
protected override void start()
{
GetComponent<CameraArm>().ArmLength = armLength;
GetComponent<Camera>().FOV = Settings.cameraFOV;
}
protected override void update()
{
if (GameManager.Instance.GamePause || !GameManager.Instance.stealFoodPopUpDone)
{
return;
}
CameraArm arm = GetComponent<CameraArm>();
if (arm)
{
Vector2 vel = Input.GetMouseVelocity();
if(inverseYControls)
arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF;
else
arm.Pitch += vel.y * turnSpeedPitch * Time.DeltaTimeF;
if (inverseXControls)
arm.Yaw -= vel.x * turnSpeedYaw * Time.DeltaTimeF;
else
arm.Yaw += vel.x * turnSpeedYaw * Time.DeltaTimeF;
if (arm.Pitch > pitchUpperClamp)
{
arm.Pitch = pitchUpperClamp;
}
else if (arm.Pitch < pitchLowerClamp)
{
arm.Pitch = pitchLowerClamp;
}
}
}
}
}