Can't flip the character other way around
worked it out But when i changed my animation a bit And then out of the blue something happened the character was not flipping when moved backwards i dont know why but the code is alright according to me. help plz INFO: it should flip the chaacter th main player along the x axis i.e. when moved left side and then when moved right it should flip it again. it was working but it is not now i dont know what triggered the change but i really just changed the walking animation a bit plz help ..
if (Input.GetKeyDown(KeyCode.P))
{
if (paused)
resume();
else
pause();
}
float x = Input.GetAxisRaw("Horizontal");
if (x == 1)
{
rb.velocity = new Vector2(moveSpeed, rb.velocity.y);
anim.SetBool("walk", true);
if (facing == -1)
{
transform.localScale = new Vector3(transform.localScale.x * -1, transform.localScale.y, transform.localScale.z);
anim.transform.Rotate(new Vector3(0, 180, 0));
}
facing = 1;
}
else if (x != -1)
{
anim.SetBool("walk", false);
rb.velocity = new Vector2(0, rb.velocity.y);
}
if (x == -1)
{
if (facing == 1)
{
Debug.Log("flipped");
anim.transform.Rotate(new Vector3(0, 0, 70));
facing = -1;
transform.localScale = new Vector3(transform.localScale.x * 3, transform.localScale.y, transform.localScale.z);
}
rb.velocity = new Vector2(-moveSpeed, rb.velocity.y); anim.SetBool("walk", true);
}
"Not working" is a fairly useless way of describing a problem. What do you expect it to do? What does it actually do? What did you change since the last time it was working? What error messages do you receive?
You appear to be rotating by 180 degrees about the y axis and inverting the local x scale - I would have thought that either one of these would achieve what you're after, but doing both cancel each other out:
transform.localScale = new Vector3(transform.localScale.x * -1, transform.localScale.y, transform.localScale.z);
anim.transform.Rotate(new Vector3(0, 180, 0));
@tanoshimi actually i am rotating the character by multiplying the scale by -1 and then rotating the animation of the player by y axis so that the animation matches the player..
Answer by nerds89 · Dec 19, 2016 at 02:21 AM
@tanoshimi i found the answer. the crouch animation was interfering in a sense the scale value was stored in the animation so the flipping of the character was not possible now its functioning properly
Your answer
Follow this Question
Related Questions
Issues with making a climbing script compatible with CharacterController 0 Answers
Character moves opposite ways.,My character moves perfectly to every direction except -z. 0 Answers
How can I modify this to allow jumping with space? 0 Answers
Character wont shoot to the left in Unity 2D 0 Answers
Why is my character flying off screen? 0 Answers