- Home /
How do I flip my 2d pixel character left and right with a different animation?,how do I flip my 2d pixel character left and right in a non weird manner?
So I’ve got my player to flip on not a weird manner but when I added the gun sprite animation when the player flips in creates a gap kinda thing I don’t know how to fix it I’m still kinda new at this programming thing,See I already have made it so the player can it can flip in not a weird way but when I added a gun sprite animation It started to flip in a weird manner what should I do
Answer by mlnczk · Nov 23, 2018 at 08:56 AM
You should try just rotating whole player ( parent witch children ) 180 degrees on Y axis. Make sure gun is a children of player and whenever you want to flip, propably checking Input in Update then do:
void Update(){
if(Input.GetKeyDown(KeyCode.A) { // we flip
transform.rotation = Quaternion.Euler(transform.rotation.x, 180, transform.rotation.z);
}else if(Input.GetKeyDown(KeyCode.D)) { // we back to normal going right
transform.rotation = Quaternion.Euler(transform.rotation.x, 0, transform.rotation.z);
}
}
See that wouldn’t work because it’s a 2d pixel game for the idle and walking animation I made it so it rotates by changing the local scale but the problem is the animation when made the sprites for the gun it doesn’t properly flip Yours would work in a 2d game though
Answer by lvoryyy · Jun 10, 2020 at 09:34 AM
Yo sorry this is super late, I thought id help others out but there's actually a really simple way
private SpriteRenderer sprite;
void Start()
{
sprite = GetComponent<SpriteRenderer>();
}
void Update()
{
if (Input.GetKey(KeyCode.A))
{
sprite.flipX = true;
}
if (Input.GetKey(KeyCode.D))
{
sprite.flipX = false;
}
}
Your answer
Follow this Question
Related Questions
How to sync animation if animation should be use with specially object 0 Answers
What is the best/easiest way to align a 2D rigidbody to specific sections of a sprite? 1 Answer
Having some stuck issues on the 2D infinite runner 0 Answers
,Spawning snow or changing tilesets to snow as the player walks past them 0 Answers
2D Sprite Fillup without using UI 1 Answer