Playmaker Forum

Playmaker Help & Tips => Playmaker Help => Topic started by: HeathClose on April 18, 2017, 05:01:51 PM

Title: Speed Based Animations with Move Towards? [SOLVED]
Post by: HeathClose 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?
Title: Re: Speed Based Animations with Move Towards?
Post by: jeanfabre 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:

(http://i.imgur.com/jTGN41N.png)

Bye,

 Jean
Title: Re: Speed Based Animations with Move Towards?
Post by: HeathClose 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:

(http://i.imgur.com/jTGN41N.png)

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.
Title: Re: Speed Based Animations with Move Towards?
Post by: HeathClose 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...
Title: Re: Speed Based Animations with Move Towards?
Post by: jeanfabre 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

Title: Re: Speed Based Animations with Move Towards?
Post by: HeathClose 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
Title: Re: Speed Based Animations with Move Towards?
Post by: jeanfabre on April 21, 2017, 01:02:57 AM
Hi,

 it works fine here:

(http://i.imgur.com/8eOKLap.gif)

 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
Title: Re: Speed Based Animations with Move Towards?
Post by: HeathClose 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?
Title: Re: Speed Based Animations with Move Towards?
Post by: HeathClose on April 23, 2017, 06:52:06 AM
is there a 2d version of this?
Title: Re: Speed Based Animations with Move Towards?
Post by: tcmeric on April 23, 2017, 07:02:23 AM
Did the 3d version not work? Get game object speed?
Title: Re: Speed Based Animations with Move Towards?
Post by: HeathClose 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
Title: Re: Speed Based Animations with Move Towards?
Post by: tcmeric 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.
Title: Re: Speed Based Animations with Move Towards?
Post by: HeathClose 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
Title: Re: Speed Based Animations with Move Towards?
Post by: tcmeric 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).
Title: Re: Speed Based Animations with Move Towards?
Post by: jeanfabre 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
Title: Re: Speed Based Animations with Move Towards?
Post by: tcmeric on April 23, 2017, 11:50:52 PM
Cool, thanks for the info. You can nuke my action then  ;D
Title: Re: Speed Based Animations with Move Towards?
Post by: HeathClose on April 24, 2017, 08:05:22 AM
hey guys thank you so much for the effort and attention... I really appreciate the help... I can't say it enough...

so i had the crazy thought to add a child object to my character and put a rigidbody on it (even though my character has one) and then put that game object speed action on the child, and it works... its returning data... I should be able to use that for the animations...

I don't know why it would work on the child with a rigidbody and not the parent with a rigidbody... but at this point, I'll take it...

Thanks again for the attention.