mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 19:10:32 +00:00
Teleport by X
This commit is contained in:
parent
6aabc65d1d
commit
0f08a2f45f
@ -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;
|
||||||
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user