Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - amit

Pages: [1]
PlayMaker Help / Reverse Animation in Mecanic - Recording & Playback
« on: November 26, 2014, 03:12:27 AM »

I am trying to find out how to use playmaker and Mecanim actions to rewind a player movement. I was suggested that Mecanim did that well so I explored it and stumbled upon someone who made this video here:

He has a snippet of sample code that he used to do this, here:

Code: [Select]

    using UnityEngine;
    using System.Collections;
    public class PrinceOfUnity : MonoBehaviour {
            public float Speed = 1;
            private float reverseSpeedTarget = -1;
            private float reverseSpeedTime = 0.3f;
            private float reverseSpeedVelocity;
            protected Animator animator;
            void Start ()
                    animator = GetComponent<Animator>();
            // Update is called once per frame
            void Update ()
                    float axis = Input.GetAxis("LeftRightTrigger");
                    Speed = Mathf.SmoothDamp(Speed, axis > 0.1f ? reverseSpeedTarget : 1, ref reverseSpeedVelocity, reverseSpeedTime);
                    animator.speed = Speed;

Link if you prefer that:

My challenge is to replicate this using playmaker and so far I made Set Animator Speed work, but it only rewinds a few frames and then it becomes buggy in terms of movement afterwards and a few other things. Also, if you jump and rewind from a higher place, it doesn't work.

[EDIT] I fixed it some more by using Animator Start Recording - Get Mouse Button Down - Set Animator Speed - Get Mouse Buttown Down - Set Animator Speed. However it isn't good enough because when I go back and forth the animation stops in mid air because that is where I started the recording again, so maybe there is a way to store the recordings everytime in an array for my tutorial example? So if I ran around for 3000 frames (which is the limit) it will always playback 3000 frames regardless of the recording stop and play time?

Could someone who knows C# explain this code by breaking it apart and logically help by referring to what could be the Playmaker action and Animator tools that is needed to pull this off? I want to be able to store recording of the last 3000 (whatever the limit is) seperate from the last time you activated "rewind". So one button will let you go back and forth between one recording when you click left and right mouse button. But if you wanted to go all the way back somewhere you could click middle button, which would then include your crazy back and forth left/right mouse button too. But right now it stops in midair when you start recording and set speed back and forth, because it deleted the rest of the animation/recording.

I just want to make it into a tutorial video so others can use it easily. :)

Thank you!

- Amit

Pages: [1]