я пытаюсь создать вращение персонажа на y с помощью вращения камеры
мне уже удалось создать движение с направлением камеры, но камера вращается без вращения персонажа, я просто пытаюсь добиться такого поведения "вращение персонажа с камерой"я использую камеру
с использованием System.Collections;
с использованием System.Collections.Generic;
с использованием UnityEngine;
открытый класс MovmenetWithCamera: MonoBehaviour
{
Vector3 _CharacterDirection, realativedir;
Quaternion _CharacterRotation;
Animator _CharacterAnim;
Rigidbody _CharacterRigidbody;
[SerializeField]
float TurnSpeed = 8, speed = 6;
bool _IsWalking;
void Start()
{
_CharacterAnim = GetComponent<Animator>();
_CharacterRigidbody = GetComponent<Rigidbody>();
}
void Update()
{
CharacterActions();
}
void FixedUpdate()
{
CharacterMovement();
}
void CharacterMovement()
{
//movement input's
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
_CharacterDirection.Set(h, 0, v);
// convert the character dir to cam dir
realativedir = Camera.main.transform.TransformDirection(_CharacterDirection);
realativedir.y = 0f;
realativedir.Normalize();
//bool movement check
bool _IsHorizontalChange = !Mathf.Approximately(h, 0f);
bool _IsVerticalChange = !Mathf.Approximately(v, 0);
_IsWalking = _IsHorizontalChange || _IsVerticalChange;
_CharacterAnim.SetBool("IsWalking", _IsWalking);
//change character forward to the desired one
Vector3 _DesairdForward = Vector3.RotateTowards(this.transform.forward, realativedir, TurnSpeed * Time.deltaTime, 0);
_CharacterRotation = Quaternion.LookRotation(_DesairdForward);
//RigidBody Direction && Rotation
_CharacterRigidbody.MovePosition(_CharacterRigidbody.position + realativedir* speed * Time.deltaTime);
_CharacterRigidbody.MoveRotation(_CharacterRotation);
}
void CharacterActions()
{
if (Input.GetKey(KeyCode.Space))
{
_CharacterAnim.SetTrigger("Shoot");
Debug.Log("shoot");
}
else if (Input.GetKeyDown(KeyCode.Space) && _IsWalking)
{
_CharacterAnim.SetTrigger("Shoot");
}
}
}