59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
![]() |
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using BITKit;
|
||
|
using BITKit.Entities;
|
||
|
using KinematicCharacterController;
|
||
|
using UnityEngine.InputSystem;
|
||
|
using UnityEngine.InputSystem.Interactions;
|
||
|
namespace BITFALL.Entites
|
||
|
{
|
||
|
public partial class EntityKinematicMovement : EntityInputComponent, ICharacterController
|
||
|
{
|
||
|
public override void OnView(InputAction.CallbackContext context)
|
||
|
{
|
||
|
if (BITAppForUnity.AllowCursor)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
var playerConfig = Data.Get<PlayerConfig>() ?? new();
|
||
|
var ads = Data.Get<float>(_ads);
|
||
|
if (ads is 0) ads = 1;
|
||
|
var raw = context.ReadValue<Vector2>() * playerConfig.sensitivity * playerConfig.m_yaw * ads;
|
||
|
var _lookInput = raw;
|
||
|
lookInput.x -= _lookInput.y;
|
||
|
lookInput.y += _lookInput.x;
|
||
|
lookInput.x = Mathf.Clamp(lookInput.x, -80, 80);
|
||
|
entity.Set(_angularVelocity, raw);
|
||
|
}
|
||
|
public override void OnMovement(InputAction.CallbackContext context)
|
||
|
{
|
||
|
var _input = context.ReadValue<Vector2>();
|
||
|
moveInput.x = _input.x;
|
||
|
moveInput.z = _input.y;
|
||
|
}
|
||
|
public override void OnRun(InputAction.CallbackContext context)
|
||
|
{
|
||
|
if (context.performed)
|
||
|
{
|
||
|
runState.shouldBe = true;
|
||
|
crouchState.shouldBe = false;
|
||
|
}
|
||
|
}
|
||
|
public override void OnJump(InputAction.CallbackContext context)
|
||
|
{
|
||
|
if (context.started)
|
||
|
{
|
||
|
jumpState.shouldBe = true;
|
||
|
}
|
||
|
}
|
||
|
public override void OnCrouch(InputAction.CallbackContext context)
|
||
|
{
|
||
|
if (context.started && groundState)
|
||
|
{
|
||
|
runState.shouldBe = false;
|
||
|
crouchState.shouldBe = !crouchState.shouldBe;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|