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.