Now that the mallet moves, we are going to make it interact with a puck. When the mallet touches the puck, we are going to apply a force to it in the opposite direction.
You can click the Play button in the toolbar and see how the mallet moves based on the mouse position. You will notice that it collides with the walls, follows the mouse cursor smoothly, and changes its movement speed based on how fast and far you move your mouse.
-3
, 0.85
, 0
). Set its scale to (1
, 0.7
, 1
).0.1
, uncheck Use Gravity, open the Constraints section, and check Freeze Position Y and Freeze Rotation X, Y and Z.65
, 60
, 60
) material (Assets | Create | Material) called PuckMaterial and assign it to the puck's Mesh Renderer.Push
in the Add Event field near the bottom of the tab, and press Return on your keyboard.Push Puck
. Right-click on the Move state in the FSM view and select Add Transition | Push from the contextual menu. A new light label saying Push should appear below the Move state. Click on it and drag the line that appears to the Push Puck state. This line is the transition that will happen once the Push event is called in the Move state. Add a FINISHED event to the Push Puck state the same way. You do not need to create it, because it is a default Playmaker event.20
. This value will determine how hard the mallet pushes the puck.pushDir
. Click on the small option () icon next to Subtract Vector. This will allow you to pick a variable from the list instead of using a numeric value. Set Subtract Vector to hitPos
.
0
and are simply not assigned instead. Click the small option icon to show the None option if needed. Then set Space to World.Your puck should now become interactive if you click on play and make the Mallet collide with it. I realize that the last bit was a lot of actions at once, so we will discuss what exactly happens in those actions in the next chapter. This is an example of some complex logic that we will look into when we talk more about game mechanics. For now consider it an exercise to familiarize yourself with actions and variables and the way they are added and assigned in the playMaker panel.
As another exercise, save your scene, create a few new game objects with FSMs, and try to experiment with different actions and variables, see how they are added and assigned. Don't worry if your actions do not do much. Try to familiarize yourself with the Playmaker interface and remember how to add, move, and remove actions, create new variables and events, and assign them.
Once you feel like you are comfortable with these actions, you can delete the objects you used for practice or simply reload the scene without saving it by double-clicking the Scene1
file in the Project panel.
3.140.197.167