Okay so I am working in Unity 2D. I have a stick figure consisting of a parent object and several child objects, including the main camera and the limbs of the character. I have a player controller attached. When I move, the arms and legs are supposed to swing at certain speeds depending on how fast the character is moving. To do this I just have a ‘rotation’ script (flipped horizontally in the case of half of the limbs) and a ‘fast rotation script’ which are toggled depending on the character’s speed. Here’s the script for one of the arms:
//using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rotation : MonoBehaviour {
private int b;
void FixedUpdate () {
b = PlayerController.b;
float y = transform.localEulerAngles.z;
transform.RotateAround (transform.position, Vector3.forward, b*45*Mathf.Sin(3*Time.fixedTime)-y);
}
}
//
(‘b’ is just a variable telling me what way the guy is facing).
Here’s the problem: this works fine when the character is facing right. However, I have code to flip the character when he faces left:
//Code that flips the character
void Flip(){
Vector3 myscale = rb.transform.localScale;
myscale.x *= -1;
rb.transform.localScale = myscale;
}
Whenever my character faces to the left, the rotation animations completely break down. When he is facing right, for instance, his second leg bounces between -20 and 50 degrees. When he is facing left it spins wildly out of control. What’s happening?