1
\$\begingroup\$

I want to move one of my GameObject to a different vector 3 position, when animator transit to a new state. How do I do it? Also there shouldn't be any delay.

\$\endgroup\$
1
  • \$\begingroup\$ Can you show some code of what you've tried? \$\endgroup\$
    – majidarif
    Nov 24, 2016 at 11:38

2 Answers 2

1
\$\begingroup\$

You Don't need to moving via animating. You can simply make a method that first change the animation state and then move object using Translate method( for instant transition) and MoveTowards or some other methods. Something like this :

Public myMethod (){
animator.set...();
transform.translate...
}

And whenever you call myMethod you have two behaviors together.

\$\endgroup\$
1
  • \$\begingroup\$ Thanx this gave me a good hint to use a Behaviour, So found a solution, posting below \$\endgroup\$
    – Thanu
    Nov 28, 2016 at 0:43
0
\$\begingroup\$

This is the solution I came up with, In my Animator state I added a behaviour script, that moves the object before the animation starts,

enter image description here

Script is a very simple C# script:

using UnityEngine;
using System.Collections;

public class BehaviorMoveGameObject : StateMachineBehaviour {

    public float Position_X;
    public float Position_Y;
    public float Position_Z;

// OnStateEnter is called when a transition starts and the state machine  starts to evaluate this state
    override public void OnStateEnter (Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {

        animator.gameObject.transform.position = new Vector3 (Position_X, Position_Y, Position_Z);

    }

}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .