コード例 #1
0
    private Vector2 getDestinationRelativeTo(Vector2 point, float distanceFromPoint, TravellingDirection travellingDirection)
    {
        const float xDifference = point.x - location.x; // Get the x distance
        const float yDifference = point.y - location.y; // Get the y distance

        // Find the desired angle in radians to travel, adding pi if wanting to go away from the target instead of towards
        const double angle = Math.Atan2(yDifference, xDifference) + (travellingDirection == TravellingDirection.away ? Float(Math.PI) : 0);

        // Get the desired x and y coordinates for the desired position based on the AI's constraints
        const double newX = point.x + distanceFromPoint * Math.Cos(angle);
        const double newY = point.y + distanceFromPoint * Math.Sin(angle);

        const Vector2 newDestination = Vector2(x: newX, y: newY);

        return(newDestination);
    }
コード例 #2
0
        private Vector2 getDestinationRelativeTo(Vector2 point, float distanceFromPoint, TravellingDirection travellingDirection)
        {
            float xDifference = point.X - position.X; // Get the x distance
            float yDifference = point.Y - position.Y; // Get the y distance

            // Find the desired angle in radians to travel, adding pi if wanting to go away from the target instead of towards
            float angle = (float)Math.Atan2(yDifference, xDifference) + (travellingDirection == TravellingDirection.away ? (float)(Math.PI) : 0);

            // Get the desired x and y coordinates for the desired position based on the AI's constraints
            float newX = (float)(point.X + distanceFromPoint * Math.Cos(angle));
            float newY = (float)(point.Y + distanceFromPoint * Math.Sin(angle));

            Vector2 newDestination = new Vector2(x: newX, y: newY);

            return(newDestination);
        }