Get the raycast direction from the position of the player and the throwing object

Viewed 19

I want to know how I should rotate my Raycast start point (Raycast direction) when I want to get an object in front of the Object from the player's perspective.

This is how I like to use it.

startTransform.eulerAngles = ???;
if (Physics.Raycast(startTransform.position, startTransform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, _layerMask))
{
        Debug.DrawRay(startTransform.position, startTransform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
}

Thanks for your help

1 Answers

I only had to find out the direction. Vector3 direction = startTransform.position - playerPosition;

Related