playMaker

Author Topic: Help with character movement based on position of object  (Read 1350 times)

Adam Z

  • Full Member
  • ***
  • Posts: 207
Help with character movement based on position of object
« on: November 21, 2019, 10:20:55 AM »
Hi. So I'm trying to animate a character based on a position of an object. My character has an animator controller with forward, backward, and strafing movements. A typical multi-directional movement system (2D Freeform Directional).

So what I'm doing is using a 'Get Position > Self' in both X and Z of that object. The object does fluctuate slightly, so it might start at an X: 0.135 and a Y: -0.0214, etc. but fluctuate by .1 or .2 in +- on X and Z.

Ideally what I would like to do is if the object in X is equal to or greater than 0.5, then start my characters forward movement by using a 'Set Animator Float'. But what I need is when X is at 0.5 then the set the Animator variable called 'Forward' to 0.1 so the character is slightly moving. And if X is 1.0 for example, have 'Forward' be at 1.0.

Because the object isn't centered at 0,0 and fluctuates, I need to adjust for that. I also would like this all in one state so multiple 'Set Animator Float' Actions can be use for all directions.

So I'm trying to figure out all the Actions I need to accomplish this:
'Get Position > Self' so I know the starting X and Z of the object.

An Action(s) that says if X is 0.5 then set float in animator to 0.1. If X is 1.0 then set float in animator to 1.0.

Any thoughts would be helpful. Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Help with character movement based on position of object
« Reply #1 on: January 07, 2020, 04:14:49 AM »
Hi,

 I think you should use blendTree, which does exactly what you are after:

https://docs.unity3d.com/Manual/class-BlendTree.html

Bye,

 Jean