Make the game#
You will need to specialize 3 classes in C++.
ACPPlayerStateto expose SetScore to blueprint, this will be used to create a custom reward functionACPPawnto make the pawn hostile to everybody, this makesAISense_Sightsense all the pawn that are in rangeACPGameModeto provide a customHasMatchEndedthat is used to reset the environment
From there everything can be done in blueprint. You will need to create the blueprints below.
Level:
CartPoleGameMode_CartPoleinherited fromCPGameModePawn_Cart(inherited fromPawn)Pawn_Pole(inherited fromCPPawn)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
FloatingPawnMovementcomponent to enable the cart’s movementThe 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