Пример #1
0
    /*
     * This enemy only attacks if it's behind the player
     * Dot product will give us orientation : 0 is 90 degree, 1 is in front, -1 is behind
     */

    private float DotToPlayer()
    {
        Vector3    playerToMe = gameObject.transform.position - player.transform.position; //get direction from player to me
        PlayerBody pb         = player.GetComponentInChildren <PlayerBody>();              //Get the player body, so I can see what direction the body is looking

        Debug.DrawRay(player.transform.position, pb.GetForward(), Color.green);
        float dotProduct = Vector3.Dot(playerToMe.normalized, pb.GetForward().normalized);

        return(dotProduct);
    }