- Home /
Local scale flip is breaking rotation
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?
Answer by Dorthonion · Dec 31, 2017 at 03:23 PM
Edit: I mean his second leg bounces between 315 and 360 degrees.
Your answer
Follow this Question
Related Questions
Make an NPC follow player on collision, ala Yoshi collecting eggs. 1 Answer
Using animated transform to push object away? 2D 0 Answers
Having some stuck issues on the 2D infinite runner 0 Answers
How to flip 2d character walk movement? 3 Answers
What is the best/easiest way to align a 2D rigidbody to specific sections of a sprite? 1 Answer