Inventory mechanics

Well, it’s up. Time to test some inventory mechanics. Start with an LBPawn (xc_char), which has been already set up. The character itself doesn’t seem to have any hands, so it uses its mouth to pick up objects. It’s quite a complex task to make a correct body and neck bend animation (it’s still not correct). Well, handling hand animations is even hareder. But in future I’ll think about it. Maybe.

To handle all interactions the pawn interactable controller is used (LBPawnInteractableController), which is a part of mechanism system. All actions are set in the editor by setting names of corresponding animations.

pawn_action_list

All animation names are linked to animtree nodes, and the slider node (blendbyaction) is controlled from the code.

animtree_example

For example, the slider for drop down action is set to child number five on activation of interaction number six (full code).

else if (value == 6)
 {
  //activate interaction: Drop down
  if (curaction != 0)
   return; 
  if (!CheckInteractioConditions(3))
  {
   LogError("proc: ActivateInteraction() return: [CheckInteractioConditions(3)] returned false!"); 
   return; 
  }
  blendbyaction.SetActiveChild(6, 0.5);
  actionseqs[5].SetPosition(0.0, false);
  actionseqs[5].PlayAnim(false, 0.8, 0.0); 
 }

Yes, slider control is hard-coded in the mechanism, it’s a shame, I know. Then, the animation is played. It fires animation notifies, which are set in the begining, the middle, where the action is performed and in the very end. Each one of them calls its own part of code (full code).

else if (notifynode.NodeName == 'Interaction_DropDown')
 {
  if (notifytype == AnimNotifyTypes_ActionStart)
  {
  curaction=6;
  }
  else if (notifytype == AnimNotifyTypes_PerformAction)
  {
   PerformInteraction(3);
  }
  else if (notifytype == AnimNotifyTypes_ActionEnd)
  {
   blendbyaction.SetActiveChild(0, 0.5);
   curaction=0;
  }
 }

The PerformInteraction function performes the real work: sets all properties of invoked objects. In this case it just tells the held object’s mechanism that it’s free to go.

All inventory objects are equipped with LBAttachMechanism.( I don’t use the default attach system, because it’s a total hemorrhoid). And the pawn has its counterpart – the LBInventoryPawnMechanism, which does all the work.

inv_mech.png

It has a modifiable parameter – a socket, where all inventory is attached (in our case – a mouth). When needed, the parameter of this mechanism (InventoryMechanism) is set to certain actor. After several checks it adds this actor to inventory or doesn’t add this actor because it’s impossible. It could be implemented with one interaction from pawn controller mechanism.

SetTargetParam(parent, InventoryMechanism, 'AddObject', otheractor);

The other actor is selected from all actors in specified area in LBAreaCheckingMechanism based on the distance from the center of this area. It’s still not the best solution, because each time it uses an iterator, wich iterates through many objects in the level. I’m not using the default collision-overlapping system, because it’s a total hemorrhoid and moreover it’s a slow solution too.

Well, this was a first step towards a complex interaction system. It’s interesting, because many modern games do have quite a simple interaction systems. Even RPG games are tend to have more and more plain character-static world interaction system, but I think you can prove me wrong. Well, the result is shown below – the character is now able to pick up and put down any objects in the level.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s