playMaker

Author Topic: Speed Based Animations with Move Towards? [SOLVED]  (Read 125 times)

HeathClose

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Speed Based Animations with Move Towards? [SOLVED]
« on: April 18, 2017, 05:01:51 PM »
I'm making a 2d side scrolling runner and using move towards with ignore vertical checked to make my character run non stop towards an empty game object "finish line"... jumping and whatnot along the way to avoid fail...

I have enemies that fire things at the runner, causing knockback...

I'd like to automate the animator using speed... but get speed 2d only shows when the character is jumping becauses move towards doesn't produce a velocity...

so two questions, both one side of a coin...

Is there a better option than move towards that would allow me switch animator states by speed?

Is there a way to still use move towards that would allow me to switch animator states by speed?
« Last Edit: April 24, 2017, 08:05:36 AM by HeathClose »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 11622
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #1 on: April 18, 2017, 11:38:49 PM »
Hi,

 I would suggest that you get the speed of your gameobject and input that into your animator as a parameter then, inside your animator graph you can do all the animation switches. Check out the Unity Stealth character it's using this technic I described above.

https://www.assetstore.unity3d.com/en/#!/content/7677

 also, I made a demo on how to control this character at siggraph in 2015, you can find the project on github: https://github.com/jeanfabre/PlayMaker--Siggraph--2015--Demo/tree/master/Assets

also, you can find a sample of this character directly on the Ecosystem:



Bye,

 Jean

HeathClose

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #2 on: April 19, 2017, 09:21:06 AM »
Hi,

 I would suggest that you get the speed of your gameobject and input that into your animator as a parameter then, inside your animator graph you can do all the animation switches. Check out the Unity Stealth character it's using this technic I described above.

https://www.assetstore.unity3d.com/en/#!/content/7677

 also, I made a demo on how to control this character at siggraph in 2015, you can find the project on github: https://github.com/jeanfabre/PlayMaker--Siggraph--2015--Demo/tree/master/Assets

also, you can find a sample of this character directly on the Ecosystem:



Bye,

 Jean

Thanks for the lead Jean... I downloaded the stealth character and had a look... very cool stuff, and I pulled the movement fsm into my runner and played with it.

the get axis vector doesn't return any data unless I press the arrow keys... but the player doesn't have any movement control of the character in my runner... only jump and shoot...

is there a way to return a speed with move towards? 

or a better way to do a constant movement toward a finish line that does return a speed?

constant velocity isn't an option.. it just doesn't behave properly with knockback, I worked with it a lot to get it to work and abandoned it for move towards.

HeathClose

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #3 on: April 19, 2017, 11:34:24 AM »
or is there a way simulate holding down an arrow key so that my character runs at the finish line.. then i could use triggers to stop her...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 11622
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #4 on: April 19, 2017, 11:37:51 PM »
Hi,

 getting the speed should be done outside MoveTowards, there is a GetGameObjectSpeed on the Ecosystem. You should use this.

simulating key pressed is your call within your fsm, since you are using an action to get the axis, nothing prevents you to set the value yourself inside the result variable.

 Bye,

 Jean


HeathClose

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #5 on: April 20, 2017, 07:33:41 AM »
Hi,

 getting the speed should be done outside MoveTowards, there is a GetGameObjectSpeed on the Ecosystem. You should use this.

simulating key pressed is your call within your fsm, since you are using an action to get the axis, nothing prevents you to set the value yourself inside the result variable.

 Bye,

 Jean

thank you Jean... I got Get Game Object Speed off the ecosystem, and no matter the combination of use owner or a global variable for the object or self or world, it doesn't return any data for speed or speed vector when the object is moving

i'm using 1.8.4 and 5.5.2f1

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 11622
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #6 on: April 21, 2017, 01:02:57 AM »
Hi,

 it works fine here:



 when you struggle with an action, always try it in an empty scene with the most minimalistic setup, then work your way up with more complex setup.

Bye,

 Jean

HeathClose

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #7 on: April 21, 2017, 05:29:51 AM »
Hi,

 it works fine here:



 when you struggle with an action, always try it in an empty scene with the most minimalistic setup, then work your way up with more complex setup.

Bye,

 Jean

i see your example is 3d... does this work with 2d?

if not can anyone make a 2d version?

HeathClose

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #8 on: April 23, 2017, 06:52:06 AM »
is there a 2d version of this?

tcmeric

  • Full Member
  • ***
  • Posts: 197
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #9 on: April 23, 2017, 07:02:23 AM »
Did the 3d version not work? Get game object speed?

HeathClose

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #10 on: April 23, 2017, 08:28:22 AM »
Did the 3d version not work? Get game object speed?

no... I put it on multiple items with movement and it didn't return data on anything in the game

tcmeric

  • Full Member
  • ***
  • Posts: 197
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #11 on: April 23, 2017, 09:46:36 AM »
Try this. Not sure if it will work, but worth a try. I changed things to vector2 and removed world space (requires vector3).

Let us know if it works. If so, maybe Jean can add to the ecosystem.

HeathClose

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #12 on: April 23, 2017, 04:05:42 PM »
Try this. Not sure if it will work, but worth a try. I changed things to vector2 and removed world space (requires vector3).

Let us know if it works. If so, maybe Jean can add to the ecosystem.

thank you so much for trying, but it only gets the speed of items with a force applied to them

tcmeric

  • Full Member
  • ***
  • Posts: 197
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #13 on: April 23, 2017, 04:47:37 PM »
Hi, I made a 2d scene and tested it out. It works without force or a rigidbody.

I made two FSM.

1. has this action only
2. has "move towards" and I just choose a destination object.

It works to register the speed. I attached my screen shot if you need to see what I did.

Make sure to use the action I attached to this thread and not the one on the ecosystem already (called something similar like object speed 2d).
« Last Edit: April 23, 2017, 04:49:27 PM by tcmeric »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 11622
    • View Profile
Re: Speed Based Animations with Move Towards?
« Reply #14 on: April 23, 2017, 11:13:54 PM »
Hi,

 GetGameObjectSpeed works for 3d and 2d, I am not sure what's going on your end, but it totally works :)

 if you need to save the speed in a vector2d, you can extract the x, y or x z from the 3d and save it inside a vector2d fsm variable.

the problem with 2d is that I don't want to constraint into a specific plane, maybe you are topdown 2d, maybe vertical 2d, it could be in any 2d plane.


 Bye,

 Jean