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

70 lines
1.5 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SHADE;
namespace SHADE_Scripting
{
2022-11-21 00:12:09 +08:00
public class ThirdPersonCamera : Script
{
2022-11-21 00:12:09 +08:00
public float armLength = 2.0f;
public float turnSpeedPitch = 0.3f;
public float turnSpeedYaw = 0.5f;
public float pitchClamp = 45.0f;
public bool inverseXControls = false;
public bool inverseYControls = false;
2022-11-21 00:12:09 +08:00
protected override void awake()
{
AddComponent<Transform>();
if (!GetComponent<Camera>())
{
AddComponent<Camera>();
}
GetComponent<Camera>().SetMainCamera();
if (!GetComponent<CameraArm>())
{
AddComponent<CameraArm>();
}
}
protected override void start()
{
2022-11-21 00:12:09 +08:00
GetComponent<CameraArm>().ArmLength = armLength;
}
protected override void update()
{
2022-11-21 00:12:09 +08:00
CameraArm arm = GetComponent<CameraArm>();
if (arm)
{
2022-11-21 00:12:09 +08:00
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;
2022-11-21 00:12:09 +08:00
if (arm.Pitch > pitchClamp)
{
arm.Pitch = pitchClamp;
}
else if (arm.Pitch < 0)
{
arm.Pitch = 0;
}
}
}
2022-11-21 00:12:09 +08:00
}
}