54 lines
1.1 KiB
C#
54 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Channels;
|
|
using System.Threading.Tasks;
|
|
using VeloX;
|
|
|
|
namespace Sandbox
|
|
{
|
|
internal class LocalCar : Component, Component.INetworkListener
|
|
{
|
|
void INetworkListener.OnDisconnected( Connection channel )
|
|
{
|
|
if ( Car?.ConnectionID == channel.Id )
|
|
DestroyGameObject();
|
|
}
|
|
|
|
[Property] VeloXCar Car { get; set; }
|
|
[Property] public Vector3 CameraOffset { get; set; }
|
|
|
|
private Angles EyeAngles { get; set; }
|
|
|
|
protected override void OnUpdate()
|
|
{
|
|
if ( !Car.IsDriver )
|
|
return;
|
|
UpdateEyeAngles();
|
|
CameraSetup();
|
|
}
|
|
|
|
private void UpdateEyeAngles()
|
|
{
|
|
|
|
Angles input = Input.AnalogLook;
|
|
Angles eyeAngles = EyeAngles;
|
|
eyeAngles += input;
|
|
eyeAngles.roll = 0f;
|
|
|
|
eyeAngles.pitch = eyeAngles.pitch.Clamp( 0f - 89, 89 );
|
|
|
|
EyeAngles = eyeAngles;
|
|
}
|
|
|
|
protected void CameraSetup()
|
|
{
|
|
|
|
var cam = Scene.Camera;
|
|
cam.WorldRotation = EyeAngles;
|
|
cam.WorldPosition = WorldPosition + Vector3.Up * CameraOffset.z + cam.WorldRotation.Backward * CameraOffset.x;
|
|
}
|
|
}
|
|
}
|