Question by
planetixin · Jan 27, 2021 at 12:33 PM ·
rotationmousespeedmeasure
how can I make player rotate towards mouse and measure the speed of that rotation?,
I'm trying to make that player could rotate towards mouse and measure the speed of that rotation, but when I'm doing that it's shown that velocity is zero because it teleports the rotation instead doing that by velocity.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Combat_system : MonoBehaviour
{
Vector2 mousePos;
Rigidbody2D rb;
public float rotationSpeed = 25f;
private float checkedRotationSpeed;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
checkedRotationSpeed = rb.angularVelocity * Mathf.Rad2Deg;
mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
rb.transform.position = original_position.position;
}
private void FixedUpdate() {
Vector2 lookDir = mousePos - rb.position;
float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg;
rb.rotation = angle;
}
}
Comment