- Home /
Question by
BlueInfernoCode · Aug 25, 2021 at 12:09 AM ·
camerarotationmousepositionworldtoscreenpoint
Cinemachine not working with my Movement Script
So, I have a script that rotates the player towards the mousePos. And when I put cinemachine to follow the player, my player doesn't rotate towards the mousePos. And I think it's because of using the position of the camera. But is there any other way to make the camera follow my player without messing up my movement script?
[SerializeField]
private float _moveSpeed = 5;
[SerializeField]
private Rigidbody2D _rb;
[SerializeField]
private Camera _cam;
Vector2 movement;
Vector2 mousePos;
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
mousePos = _cam.ScreenToWorldPoint(Input.mousePosition);
}
private void FixedUpdate()
{
_rb.MovePosition(_rb.position + movement * _moveSpeed * Time.deltaTime);
Vector2 lookDir = mousePos - _rb.position;
float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
_rb.rotation = angle;
}
Comment
Your answer
Follow this Question
Related Questions
How to smoothly rotate camera around an object with touch 1 Answer
How do I stop my camera flying? 0 Answers
Why is my camera not snapping 90 degrees? 0 Answers
How to force camera rotation? 1 Answer