For my implementation I want the player to rotate towards the mouse direction and only allow combo to succeed if the following click is within the time and in certain max angle difference.
Circle is the click point and I want to limit the range like this, so that player can slightly adjust the direction
I am getting a mouse position by: Vector3 mousePoint = Camera.main.ScreenToWorldPoint(Mouse.current.position.ReadValue());
I set the direction:
Vector3 direction = mousePoint - stateMachine.transform.position;
Noticed in other rotation we do we set the y to 0:
This is because direction is not a true “rotation”. That’s represented by a Quaternion, and we really don’t want to manipulate those directly. The direction is more of a line, like on a graph. by zeroing out the Y component of this, we’re only looking at the changes in the X and Y values of the direction, effectively taking the slope out of the equation. If we don’t, then when we face the character, the character will actually look like he’s tipping over if the target is at a different elevation.
Try this instead:
Vector3 GetMousePositionInWorld()
{
Ray ray = Camera.Main.ScreenPointToRay(Mouse.current.position.ReadValue());
if(Physics.Raycast(ray, out Hit hit)
{
Debug.Log($"Mouse is at {hit.Point}");
return hit.Point;
}
Debug.Log("No hits with mouse");
return Vector3.zero;
}