How do i change player position during an animation?

Hello, I’ve come across a problem recently. I’m making a endless runner. In my running animation i want him to go up and down so in my animation i used the move tool to make him go up in a part of the animation. But when i do that it of course messes up the game and my guy wont move. I believe this happens because the animator is interfering with the player controller when you move the position of the player. Someone had a similar problem and suggested making an empty parent object and putting the player controller on that. But that wont work because I think my script needs to find my players collider and rigid body. If anyone could tell me a solution to this problem by telling me how i could modify my script when its on the players parent object to make it work or another solution it would be greatly appreciated. Here is my script:

public class PlayerController : MonoBehaviour
{
public float movespeed;
public float jumpforce;
private Rigidbody2D myRigidbody;
public bool grounded;
public LayerMask whatIsGround;
private Collider2D myCollider;
private Animator myAnimator;
// Use this for initialization
void Start()
{
myRigidbody = GetComponent();
myCollider = GetComponent();
myAnimator = GetComponent();
}
// Update is called once per frame
void Update()
{
grounded = Physics2D.IsTouchingLayers(myCollider, whatIsGround);
myRigidbody.velocity = new Vector2(movespeed, myRigidbody.velocity.y);
if (CrossPlatformInputManager.GetButtonDown(“jump”) || Input.GetMouseButtonDown(0))
{
if (grounded)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpforce);
}
}
myAnimator.SetFloat (“Speed”, myRigidbody.velocity.x);
myAnimator.SetBool (“Grounded”, grounded);
}
}

Thank you for your help.

Hi, I had similar troubles. You can solve your problem if you place all your physics relating stuff and components in the parent object, and the animator and sprite renderer in the child game object. You just have to separate these components and don’t mix them together in one single game object, like you did. Regarding your script that means: Put your Rigidbody2D and Collider2D in the parent, the Animator has to be in the child. Now also split your **PlayerController-**Script into one script for the parent; i.e. PlayerPhysicsController, where you do all your physics stuff and one **PlayerAnimationController-**Script for your child object, where you can access the Animator-component.
Hope this helps, I couldn’t find any alternative yet and also didn’t get help/support on this topic yet. Maybe this is a non reported bug in unity, cause this behaviour makes no sense to me at all …