playMaker

Author Topic: Am I doing this right?  (Read 3824 times)

ruairiau

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Am I doing this right?
« on: March 30, 2016, 06:55:51 PM »
Hi everyone,
I'm a seasoned developer but I'm new to games development. Initially I was scripting everything which was fun, but after seeing some videos on Playmaker I was quickly sold on its ability for rapid design and development - I'm now just trying to wrap my brain around understanding everything within the context of a state machine and when best to use them over scripting.

I'm making a simple dungeon crawler and putting together some basic melee combat. I'm trying to work out what my options are for notifying enemies when my character swings his sword.
I've seen posts/tutorials that discuss using a box collider as a trigger and putting it around the sword; however my character only has a little sword (which he's very proud of) and the animation doesn't swing very far out, so collision might be hit or miss literally - an option might be to extend the collider to be larger than the sword. I've seen others talk about raytracing, but this looks a little complicated.

What I've settle on for now is putting a box collider trigger slightly infront of my character, then I use an FSM to add or remove gameobjects which have an 'Attackable' tag to an array as they enter or exit the box collider trigger. Then when I attack, the FSM loops through each game object in the array and sends an Attacked event. Is this a terrible idea? Am I doing this all completely wrong?

mdotstrange

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
    • Can't code? Who cares! Make games anyway!
Re: Am I doing this right?
« Reply #1 on: March 30, 2016, 08:21:47 PM »
If it works for you it works  :)

Other ways would be as you described, having a collider on the melee weapon that uses a trigger event to deal damage- for more control over that method- you can fire animation events from the swing animation to control the part of the animation wherein the collider is active and can deal damage- you can offset the collider so it goes out further in front of the player-

You could also cast an overlapsphere or box in the area- send the hit objects to an array and deal damage to them-

A possible issue with the method you described is making sure the box collider is only active/does damage during the correct part of the sword swing animation- you can use animation events to control that-

Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

ruairiau

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Am I doing this right?
« Reply #2 on: March 30, 2016, 08:33:41 PM »
A possible issue with the method you described is making sure the box collider is only active/does damage during the correct part of the sword swing animation- you can use animation events to control that-

I'm glad you brought this up. I've previously wrote scripts that could could called using the animation events (specifically these events: http://docs.unity3d.com/Manual/AnimationEventsOnImportedClips.html). How do I get Playmaker to listen to these events?

mdotstrange

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
    • Can't code? Who cares! Make games anyway!
Re: Am I doing this right?
« Reply #3 on: March 31, 2016, 12:07:10 AM »
Playmaker will automatically listen for these events- the animation events will be sent to all the fsm's attached to the object with the animator component on it-

So if you use the events the animation events fire in an fsm on the object they will be triggered-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

ruairiau

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Am I doing this right?
« Reply #4 on: March 31, 2016, 12:49:18 AM »
Playmaker will automatically listen for these events- the animation events will be sent to all the fsm's attached to the object with the animator component on it-

So if you use the events the animation events fire in an fsm on the object they will be triggered-
Wow, that's pretty neat. Thanks for the help.

mdotstrange

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
    • Can't code? Who cares! Make games anyway!
Re: Am I doing this right?
« Reply #5 on: March 31, 2016, 02:25:00 AM »
Animation events are really cool  :)
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

ruairiau

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Am I doing this right?
« Reply #6 on: March 31, 2016, 03:32:57 AM »
I cannot get this to work at all. I keep getting "'PlayerFSM' AnimationEvent 'SendEvent("MeleeHit")' has no receiver! Are you missing a component?"

Any pointers?
 

ruairiau

  • Playmaker Newbie
  • *
  • Posts: 5
    • View Profile
Re: Am I doing this right?
« Reply #7 on: March 31, 2016, 05:08:29 AM »
Ok I've managed to figure this out. I'll detail the issue here in case other newbies like me come across this.

There are 2 ways to trigger events in animations in Unity, using the Animation Window (Ctrl + 6) or if you select an FBX file with embedded animations.

Animation:
If you add an event to the timeline and see no functions listed, make sure you only have one FSM on the GameObject. Having more than one will cause the list to be empty.

It should look like this...


FBX:
Select the animations tab in the FBX, then select the  animation from the clips list...


Go down and expand Events, then in the preview window scroll along the timeline to where you want the event, click add event. Type SendEvent into the function, then type the name of the transition event in your FSM.



 


mdotstrange

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
    • Can't code? Who cares! Make games anyway!
Re: Am I doing this right?
« Reply #8 on: March 31, 2016, 02:35:19 PM »
Another thing that can make working with animation events a little smoother is if you are working with clips from an imported fbx like it appears you are- make an "editable" copy of the clip by selecting it and doing ctrl-D then use and work with the copy-



It will allow you to place/edit new events on the animation timeline- if you don't use a copy Unity may not save the events after closing the project or allow you to add them at all
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!