I’m trying to check whether the player is facing towards an object that they’re colliding with. I know that they player is colliding with the object itself but the raycast that Im sending seems to be acting peculiarly.
if((movement.collisionFlags & CollisionFlags.Sides) != 0)
{
Vector3 start = transform.position;
Vector3 temp = transform.position;
float opp = Mathf.Sin(transform.eulerAngles.y * Mathf.Deg2Rad) *2;
float adj = Mathf.Cos(transform.eulerAngles.y * Mathf.Deg2Rad) *2;
temp.x += opp;
temp.z += adj;
RaycastHit hit = new RaycastHit();
if(Physics.Raycast(start, temp, out hit, 1.0f))
{
Debug.Log (hit.collider);
}
Debug.DrawLine (start, temp, Color.green, 15.0f, true);
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Sphere);
cube.transform.position = temp;
}
The primitive appears in the correct spot and the line intersects with the object but the raycast still fails. Except on one side where regardless of the direction the player is facing the raycast still succeeds. Again the primitive is in the correct spot and the drawline will avoid the object but it still succeeds regardless. There must be something Im missing but I cant see it.