Move through camera direction. Simple x-ray shader for player
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using FishNet.Object;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -8,6 +7,15 @@ namespace Players
|
||||
{
|
||||
[SerializeField] private float _moveSpeed = 5f;
|
||||
[SerializeField] private CharacterController _characterController;
|
||||
|
||||
private Transform _cameraTransform;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Camera playerCamera = GetComponentInChildren<Camera>(true);
|
||||
if (playerCamera != null)
|
||||
_cameraTransform = playerCamera.transform;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
@@ -16,10 +24,14 @@ namespace Players
|
||||
|
||||
float horizontal = Input.GetAxisRaw("Horizontal");
|
||||
float vertical = Input.GetAxisRaw("Vertical");
|
||||
|
||||
Vector3 offset = new Vector3(horizontal, Physics.gravity.y, vertical).normalized * (_moveSpeed * Time.deltaTime);
|
||||
|
||||
Transform directionSource = _cameraTransform != null ? _cameraTransform : transform;
|
||||
Vector3 forward = Vector3.ProjectOnPlane(directionSource.forward, Vector3.up).normalized;
|
||||
Vector3 right = Vector3.ProjectOnPlane(directionSource.right, Vector3.up).normalized;
|
||||
Vector3 moveDirection = (right * horizontal + forward * vertical).normalized;
|
||||
Vector3 offset = moveDirection * (_moveSpeed * Time.deltaTime);
|
||||
|
||||
_characterController.Move(offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user