Blended

Blended Steering Behaviors

This module implements a class that Blends a list of KinematicSteeringBehavior s and provides a weighted sum of their outputs as a steering request.

This is the bread and butter of Steering Behaviors since it easily combines different behaviors that allow for semi-complex AI behaviors.

Derives from KinematicSteeringBehavior.

Example

This is how you would normally create your own BlendedSteering , in this case we are making a more complex version of Arrive where the character looks where it’s going and also tries to avoid any obstacle in the way.

flocking_behavior = BlendedSteering(
    character = character
    behaviors = [
        BehaviorAndWeight(kinematic.Arrive(character, target), weight = 1),
        BehaviorAndWeight(kinematic.LookWhereYoureGoing(character), weight = 1),
        BehaviorAndWeight(kinematic.ObstacleAvoidance(character, obstacles), weight = 2),
    ]
)

This module also includes a couple of pre-implemented BlendedSteering.

Todo

Make BehaviorAndWeight prettier, maybe use named tuples?

BehaviorAndWeight

class steering.blended.BehaviorAndWeight(behavior, weight)[source]

Container for Behavior and Weight values

Parameters:

BlendedSteering

class steering.blended.BlendedSteering(character, behaviors)[source]

Base Blended Steering

This class provides methods neccesary to combine the list of steering behaviors and produce a single SteeringOutput.

Derives from KinematicSteeringBehavior, currently BlendedSteering with StaticSteeringBehavior is not supported.

Parameters:
draw_indicators(screen, offset=<function BlendedSteering.<lambda>>)[source]

Draws appropiate indicators for this BlendedSteering

Draws the indicators of all KinematicSteeringBehavior that compose this BlendedSteering.

Parameters:
  • screen (pygame.Surface) – Surface in which to draw indicators, normally this would be the screen Surface
  • offset (function, optional) –

    Function that applies an offset to the object’s position

    This is meant to be used together with scrolling cameras, leave empty if your game doesn’t implement one,it defaults to a linear function f(pos) -> pos

get_steering()[source]

Returns the combined steering request of this BlendedSteering

Returns:Requested steering
Return type:SteeringOutput
class steering.blended.Arrive(character, target, obstacles, target_radius=None, slow_radius=None)[source]

BlendedSteering that makes the character Arrive at a target

This is behavior is a more complex version of Arrive that also Looks Where it’s Going and tries to Avoid Obstacles.

Parameters:
class steering.blended.Flocking(character, swarm, target)[source]

BlendedSteering that makes the character move in a flock-like way

This behavior is meant to be used with several characters, they will all try to Arive at the same target location while Looking Where They’re Going and keeping Separated from eachother.

Parameters:
class steering.blended.Wander(character, obstacles)[source]

BlendedSteering that makes the character Wander around.

This behaviors is a more complex version of Wander that also tries to Avoid Obstacles.

Parameters: