Question by
d3m0nytlegit · Mar 24, 2019 at 10:40 AM ·
rotationnot working
"Not implemented"
i honestly have no idea why the camera rotation is not working and i can't figure out whats the issue heres the two scripts any help is appreciated thanks! ps i followed this video https://youtu.be/kjUiARseG18
Player control script using UnityEngine;
[RequireComponent(typeof(PlayerMotor))]
public class PlayerController : MonoBehaviour { [SerializeField] private float speed = 5f; [SerializeField] private float LookSensitivity = 3f;
private PlayerMotor motor;
void Start()
{
motor = GetComponent<PlayerMotor>();
}
void Update()
{
float xMov = Input.GetAxisRaw("Horizontal");
float zMov = Input.GetAxisRaw("Vertical");
Vector3 _movHorizontal = transform.right * xMov;
Vector3 movVertical = transform.forward * zMov;
Vector3 _velocity = (_movHorizontal + movVertical).normalized * speed;
motor.Move(_velocity);
float _yRot = Input.GetAxisRaw("Mouse X");
Vector3 _rotation = new Vector3(0f, _yRot, 0f) * LookSensitivity;
motor.Rotate(_rotation);
}
}
playermotor script using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerMotor : MonoBehaviour { private Vector3 velocity = Vector3.zero; private Vector3 rotation = Vector3.zero;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
public void Move(Vector3 _velocity)
{
velocity = _velocity;
}
public void Rotate(Vector3 _rotation)
{
rotation = _rotation;
}
private void FixedUpdate()
{
PerformMovement();
PerformRotation();
}
void PerformMovement()
{
if (velocity != Vector3.zero)
{
rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
}
void PerformRotation()
{
rb.MoveRotation(rb.rotation * Quaternion.Euler(rotation));
}
}
}
Comment
you need to re-follow the video, we cant help you if you dont know which part you got lost or tell us whats happening
Your answer
![](https://koobas.hobune.stream/wayback/20220612194109im_/https://answers.unity.com/themes/thub/images/avi.jpg)