playMaker

Author Topic: Trigger Mecanim animations when NPC charater moves?  (Read 2943 times)

stitchlips

  • Playmaker Newbie
  • *
  • Posts: 18
Trigger Mecanim animations when NPC charater moves?
« on: October 01, 2016, 10:51:09 AM »
I think I have gotten close to doing this but I am still missing something. I have an AI controller NPC that is fully rigged and loaded with animations. The animations are simply triggered in mecanim by movement. If horizontal is greater than one, then the animation for forward movement plays. If it is less than zero, then the animation for backwards movement plays. The same idea works for left and right as well.

Using PLaymaker, how could I determine when my NPC moves and then feed that movement into the mecanim animator. These movements are all mecanim floats. I can set animator float with a value and it works. What I would like to do is this.

When NPC moves this way, get movement and set NPC float accordingly. Any idea?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Trigger Mecanim animations when NPC charater moves?
« Reply #1 on: October 01, 2016, 11:58:17 AM »
Hi,
if you are using axis for the movement you can use the 'get axis' value and then use 'set animator float' to set the float in the animator,
set both to every frame

stitchlips

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Trigger Mecanim animations when NPC charater moves?
« Reply #2 on: October 01, 2016, 12:10:32 PM »
It's an NPC controlled by ai. I was under the impression that get axis was for things such as joysticks so I didn't think I could use that action for what I needed.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Trigger Mecanim animations when NPC charater moves?
« Reply #3 on: October 01, 2016, 01:46:38 PM »
Hi,
sorry i did not read the question well,

What you can do is get the position, save in a float for x,y,z separately (call it old x / y / z for example)
Then do a next frame action.
Then do a get position again (call it new x / y / z for example) and compare the floats with 'float compare' for each direction (x / y / z ) needed.
this way you can know which way the npc is going
after all directions compared loop back to the 1st state.

if (for example) old x is less than new x, set animator float x to -1

stitchlips

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Trigger Mecanim animations when NPC charater moves?
« Reply #4 on: October 01, 2016, 05:38:49 PM »
Now that is genius! Will give it a try. Thanks!

stitchlips

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Trigger Mecanim animations when NPC charater moves?
« Reply #5 on: October 02, 2016, 12:34:31 PM »
Hi,
sorry i did not read the question well,

What you can do is get the position, save in a float for x,y,z separately (call it old x / y / z for example)
Then do a next frame action.
Then do a get position again (call it new x / y / z for example) and compare the floats with 'float compare' for each direction (x / y / z ) needed.
this way you can know which way the npc is going
after all directions compared loop back to the 1st state.

if (for example) old x is less than new x, set animator float x to -1

That works. The only problem I was running into was that the float compare was so precise that it wasn't always seeing a difference in the positions. This could also be because my NPC is slow. I added a "buffer" state with a wait of .05 to give the positions time to change and now when the NPC moves, the animations trigger. When the NPC stops, it triggers the idle animation state. Thanks!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Trigger Mecanim animations when NPC charater moves?
« Reply #6 on: October 02, 2016, 01:20:41 PM »
Hi,
I am happy you got it to work :)