Flipping a capsule collider along with animation in Unity

I had this weird problem, when I flipped an animation, the capsule collider, which was also animated, was jumping all over the place.

Not much help on the forums, but this video really helped:


//so I disabled the .flipX
//and instead used

transform.eulerAngles = new Vector3(0, 180, 0);
transform.eulerAngles = new Vector3(0, 0, 0);


///

void FixedUpdate()

    {

        //if moving right

        if (flyDirection == FlyDirection.right)

        {

            // sr.flipX = true;

            transform.eulerAngles = new Vector3(0, 180, 0);


            if (Time.time - lastDirectionChangeTime < moveTime)

            {

                rb.velocity = new Vector2(moveSpeed, rb.velocity.y);

            }

            else //change directions

            {

                lastDirectionChangeTime = Time.time;

                flyDirection = FlyDirection.left;


            }

        }

        else if (flyDirection == FlyDirection.left)

        {

//            sr.flipX = false;

            transform.eulerAngles = new Vector3(0, 0, 0);



            if (Time.time - lastDirectionChangeTime < moveTime)

            {

                rb.velocity = new Vector2(-moveSpeed, rb.velocity.y);

            }

            else //change directions

            {

                lastDirectionChangeTime = Time.time;

                flyDirection = FlyDirection.right;


            }


        }

    }

Comments

Popular posts from this blog

on middlebrow

guy