Move through camera direction. Simple x-ray shader for player

This commit is contained in:
Nikita Dugin
2026-04-07 23:19:35 +03:00
parent 0e3b3a1ccf
commit 78a23c3367
16 changed files with 745 additions and 158 deletions
+16 -4
View File
@@ -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);
}
}
}
}