Teleport by X

This commit is contained in:
MrGadget1024 2023-02-24 22:53:10 -05:00
parent 6aabc65d1d
commit 0f08a2f45f

View File

@ -11,6 +11,7 @@ public enum GroundState : byte { Jumping, Falling, Grounded }
[Header("Avatar Components")] [Header("Avatar Components")]
public CharacterController characterController; public CharacterController characterController;
public NTRCustomSendInterval NTR;
public Animator animator; public Animator animator;
[Header("Materials")] [Header("Materials")]
@ -59,12 +60,15 @@ public enum GroundState : byte { Jumping, Falling, Grounded }
void OnValidate() void OnValidate()
{ {
if (animator == null) if (NTR == null)
animator = GetComponentInChildren<Animator>(); NTR = GetComponentInChildren<NTRCustomSendInterval>();
if (characterController == null) if (characterController == null)
characterController = GetComponent<CharacterController>(); characterController = GetComponent<CharacterController>();
if (animator == null)
animator = GetComponentInChildren<Animator>();
// Override CharacterController default values // Override CharacterController default values
characterController.enabled = false; characterController.enabled = false;
characterController.skinWidth = 0.02f; characterController.skinWidth = 0.02f;
@ -81,9 +85,9 @@ public override void OnStartAuthority()
characterController.enabled = true; characterController.enabled = true;
this.enabled = true; this.enabled = true;
TestNTNetworkAuthenticator.AuthRequestMessage authRequestMessage TestNTNetworkAuthenticator.AuthRequestMessage authRequestMessage
= (TestNTNetworkAuthenticator.AuthRequestMessage)NetworkClient.connection.authenticationData; = (TestNTNetworkAuthenticator.AuthRequestMessage)NetworkClient.connection.authenticationData;
if (authRequestMessage.useNinja) if (authRequestMessage.useNinja)
if (TryGetComponent(out NTRCustomSendInterval nt)) if (TryGetComponent(out NTRCustomSendInterval nt))
nt.sendIntervalMultiplier = authRequestMessage.multiplier; nt.sendIntervalMultiplier = authRequestMessage.multiplier;
} }
@ -99,6 +103,7 @@ void Update()
if (!characterController.enabled) if (!characterController.enabled)
return; return;
HandleTeleport();
HandleTurning(); HandleTurning();
HandleJumping(); HandleJumping();
HandleMove(); HandleMove();
@ -113,6 +118,20 @@ void Update()
velocity = Vector3Int.FloorToInt(characterController.velocity); velocity = Vector3Int.FloorToInt(characterController.velocity);
} }
void HandleTeleport()
{
if (Input.GetKey(KeyCode.X))
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
NTR.CmdTeleport(Vector3.up);
}
else
{
characterController.enabled = false;
transform.position = Vector3.up;
characterController.enabled = true;
}
}
// Alternative methods provided for headless clients to act autonomously // Alternative methods provided for headless clients to act autonomously
#if !UNITY_SERVER #if !UNITY_SERVER