playMaker

Author Topic: How to you equip items with PlayMaker?  (Read 1745 times)

bunnyrick

  • Playmaker Newbie
  • *
  • Posts: 12
How to you equip items with PlayMaker?
« on: April 05, 2019, 09:03:57 AM »
Hi.

I'm wondering how i can equip items that i find in the game world using PlayMaker? 
Let's suppose i find a sword and want to equip in the character's hand, how would you design a simple fsm to do this?
« Last Edit: April 05, 2019, 09:05:37 AM by bunnyrick »

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: How to you equip items with PlayMaker?
« Reply #1 on: April 05, 2019, 01:43:11 PM »
There are many other things to consider before simply equip a sword to the characters hand.

personally, I would recommend watching this series:


Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: How to you equip items with PlayMaker?
« Reply #2 on: April 05, 2019, 02:18:39 PM »
First, a system like this is intricate, but I can give you a few pointers.

1) weapon needs to have a pivot point or parent game object so that when you rotate it, it rotates at the handle. Prefab this whole thing.

2) the hand needs to have a child game object where you want the sword to attach to. Use gizmo to make it visible. Attaching is simply putting that sword as a child of this object, do this by hand, so it’s zero in the transform. Then rotate or adjust the attach game object parent so that the sword is attached correctly. Now you have this set up, you can delete or unparent the sword.

The goal is that you can just drop the sword into the attachment as child, zero tthe swords transform, and it looks correctly.

3) equipping is then, after some interaction (button press etc), parenting/child the sword to this attachment game object, or creating a sword object new. And then setting the transform to zero, so it sits correctly.

« Last Edit: April 05, 2019, 02:22:47 PM by Thore »

bunnyrick

  • Playmaker Newbie
  • *
  • Posts: 12
Re: How to you equip items with PlayMaker?
« Reply #3 on: April 05, 2019, 02:29:22 PM »
There are many other things to consider before simply equip a sword to the characters hand.

personally, I would recommend watching this series:


Ok, i'll take a look at these tutorials. Thanks.

First, a system like this is intricate, but I can give you a few pointers.

1) weapon needs to have a pivot point or parent game object so that when you rotate it, it rotates at the handle. Prefab this whole thing.

2) the hand needs to have a child game object where you want the sword to attach to. Use gizmo to make it visible. Attaching is simply putting that sword as a child of this object, do this by hand, so it’s zero in the transform. Then rotate or adjust the attach game object parent so that the sword is attached correctly. Now you have this set up, you can delete or unparent the sword.

The goal is that you can just drop the sword into the attachment as child, zero tthe swords transform, and it looks correctly.

3) equipping is then, after some interaction (button press etc), parenting/child the sword to this attachment game object, or creating a sword object new. And then setting the transform to zero, so it sits correctly.



Thanks for the answer. I don't understand much of the concept behind FSMs but i'll see if i can put together something similar to your reply.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: How to you equip items with PlayMaker?
« Reply #4 on: April 05, 2019, 06:47:05 PM »
Try something like this:

Add FSM to character. Start State, call it Ini. Here we first want to find the attachment game object, that is child of hand. If you want to do this right, prefer referencing game objects by name, or tag, etc. and rather not by drag and drop (only if the object is part of the same prefab). A game object in the scene is a concrete individual object, whereas a prefab is a blueprint that can be used to produce actual objects. So name it “WeaponHolder” or something. Then add the find child action. Thus, when the character spawns, it will look for the WeaponHolder, and remember it in a variable. Finish event...

Next state, called “unarmed”, say we wait for key down, space bar. Later on, use button down and Unity’s input manager. But for prototype or web game, keys are fine.

Next state, create game object, and reference the sword prefab. Also store the object (you need this to reference the actual sword later). Next action, set parent, to move it below the WeaponHandler, which we conveniently stored as a variable. I believe the parent  action allows to set child’s transforms to zero everything. No rotation, 0/0/0 location. That’s the point of the preparation above, because now you can make weapons that will always work when simply dropped into the WeaponHandler at zero.

After that’s done, go to next state, called “armed”. In the same manner you can reverse back to unarmed (wait for a key here, if pressed, go to next state, destroy sword, then go back to unarmed).

Well, presto, now after pressing space, the character has the weapon in hand. But that’s just the start. Now when arming, you also need to to send animation trigger, to tell mechanim to go into “armed” set of animations and so on. Also, when armed, you want to activate another FSM to do the actual attacking etc. And switch it off when unarmed etc.

It’s not easy. You can do it in a few days, but you should start with something slightly easier as a first attempt.

Another tip: stuff like that can often be created manually. I.e. what do you need to do, exactly, so that the sword appears in the hand? Is it switching on a game object? Is it parenting and zero transform a prefab instance? That means, you can do this step by step in Unity’s editor. After you figured out what you need to do, you can make an FSM, almost like a macro, that does these steps in automated fashion.
« Last Edit: April 05, 2019, 06:52:12 PM by Thore »