unity 2d how to set an object or the mouse position
Vector2 mousePos = new Vector2(camera.ScreenToWorldPoint(Input.mousePosition.x), camera.ScreenToWorldPoint(Input.mousePosition.y));
unity 2d how to set an object or the mouse position
Vector2 mousePos = new Vector2(camera.ScreenToWorldPoint(Input.mousePosition.x), camera.ScreenToWorldPoint(Input.mousePosition.y));
Unity 2D mouse look at cursor
// Note: You should cache Camera.main in Awake()
[SerializeField, Range(0, 50)] private float rotationSpeed = 25.0F;
private void Update()
{
Vector2 directionDifference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
Quaternion targetRotation = Quaternion.AngleAxis(angle, Vector3.forward);
tranform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us