Make the game

Make the game#

../../../_images/cartpole_overview.png

You will need to specialize 3 classes in C++.

  • ACPPlayerState to expose SetScore to blueprint, this will be used to create a custom reward function

  • ACPPawn to make the pawn hostile to everybody, this makes AISense_Sight sense all the pawn that are in range

  • ACPGameMode to provide a custom HasMatchEnded that is used to reset the environment

From there everything can be done in blueprint. You will need to create the blueprints below.

  • Level: CartPole

  • GameMode_CartPole inherited from CPGameMode

  • Pawn_Cart (inherited from Pawn)

  • Pawn_Pole (inherited from CPPawn)

  • PlayerState_Cart (inherited from CPPlayerState)

  • PlayerController_Cart (inherited from PlayerController)

Note

Both PlayerState_Cart and PlayerController_Cart are left empty. Your input handling could be moved to PlayerController_Cart if you wanted.

GameMode_CartPole#

Pawn_Cart#

  • Add a FloatingPawnMovement component to enable the cart’s movement

  • The cart is composed of a single cube followed by a cylinder rotated 90 degrees i.e (0, -90, 0)

  • The cube is translated (200, 0, 0) so it can be seen from the default camera

Pawn_Pole#

  • The pole is a single cylinder

  • Enable physics on the cylinder.

  • You can modify Linear Damping and Angular Damping properties to make the pole easier to balance.

You should now be able to play the game