- Home /
Slowly rotating an object while pointing at mouse
I have a player with a sword, The sword is always pointing at the mouse:
Vector3 mouse_place = Input.mousePosition;
mouse_place = Camera.main.ScreenToWorldPoint(mouse_place);
Vector3 current_place = transform.parent.position;
float y = (mouse_place.y - current_place.y);
float x = (mouse_place.x - current_place.x);
float direction = Mathf.Atan2(y, x) * Mathf.Rad2Deg;
if (x != 0 || y != 0)
{
weapon.transform.eulerAngles = new Vector3(0, 0, direction-30);
}
I want that if I press mose1 the sword will move to (direction + 30), meaning 60 degree but will still follow the mouse. A good example is from reinhardt from overwatch, he swings hes hammer but the player can still aim.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612192310im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Limiting the camera's rotation using quaternions, camera sticking to top/bottom limit angles 0 Answers
How do i make my Mouselook behave when changing the z rotation? 0 Answers
Using MouseLook script with LookAt function 2 Answers
Camera X and Y velocity HELP! 0 Answers
Using quaternion for mouse movement? 3 Answers