Необходимо сделать так, чтобы персонаж двигался по направлению куда смотрит камера: using UnityEngine;
using Cinemachine;
[RequireComponent(typeof(Rigidbody), typeof(BoxCollider))]
public class PlayerCont : MonoBehaviour
{
[SerializeField] private Rigidbody _rb;
[SerializeField] private FixedJoystick Joystick;
[SerializeField] private Animator[] animations;
[SerializeField] public CinemachineVirtualCamera CVC;
[SerializeField] private float jumpForce = 150f;
[SerializeField] private float MoveSpeed;
public void jump()
{
_rb.AddForce(new Vector3(_rb.velocity.x, jumpForce));
}
private void FixedUpdate()
{
_rb.velocity = new Vector3(Joystick.Vertical * MoveSpeed, _rb.velocity.y, Joystick.Horizontal * -MoveSpeed);
}
}
private void FixedUpdate()
{
Move(_verticalAxis, _horizontalAxis);
}
public void Move(float vertical, float horizontal)
{
Vector2 direction = new Vector2(horizontal, vertical);
direction.Normalize();
Vector3 movePosition = Vector3.Normalize(direction.x * transform.right + direction.y * transform.forward);
movePosition *= _Speed * Time.fixedDeltaTime;
movePosition += transform.position;
_rigidbody.MovePosition(movePosition);
}
Объяснение: