GhostSPJ

help1

Jul 26th, 2021
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. void handleRotation2()
  2. {
  3. //Vector3 positionToLookAt;
  4.  
  5. Vector2 mouseScreenPosition = playerInput.CharacterControls.MousePosition.ReadValue<Vector2>();
  6. Vector3 mouseWorldPosition = cam.ScreenToWorldPoint(mouseScreenPosition);
  7. Vector3 targetDirection = mouseWorldPosition - transform.position;
  8.  
  9. Vector3 positionOnViewport = cam.WorldToViewportPoint(transform.position);
  10.  
  11. float angle = AngleBetweenTwoPoints(positionOnViewport, targetDirection);
  12.  
  13. transform.rotation = Quaternion.Euler(new Vector3(0f, -angle, 0f));
  14.  
  15. //float angle = Mathf.Atan2(targetDirection.y, targetDirection.x) * Mathf.Rad2Deg;
  16. //transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, angle));
  17.  
  18. //Debug.Log("MousePos: " + mousePosition.x + " , " + mousePosition.y);
  19.  
  20. //positionToLookAt.x = currentMovement.x;
  21. //positionToLookAt.x = mousePosition.x;
  22. //positionToLookAt.y = 0.0f;
  23. //positionToLookAt.z = currentMovement.z;
  24. //positionToLookAt.z = mousePosition.y;
  25.  
  26. //Quaternion currentRotation = transform.rotation;
  27.  
  28.  
  29. //Quaternion targetRotation = Quaternion.LookRotation(targetDirection);
  30. //transform.rotation = Quaternion.Slerp(currentRotation, targetRotation, rotationFactorPerFrame * Time.deltaTime);
  31.  
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment