Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by nicolaskhumukcham · Feb 03, 2021 at 11:00 PM · 2d-platformerplatformer2d sprites2d animationanimation controller

2d character not flipping ,2D animation not Flipping. HELP

My character wont flip while having the animator turned on but when its off the character flips Here's my code using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.CrossPlatformInput;

public class movement : MonoBehaviour { public float speed; public float jumpForce; private float moveInput; private Rigidbody2D rb; private bool facingRight = true; private bool isGrounded; public Transform groundCheck; public float checkRadius; public LayerMask whatIsGround; private int extraJumps; public int extraJumpValue; public Animator animator; public GameObject GameOverText, RestartButton;

 void Start()
 {
     extraJumps = extraJumpValue;
     rb = GetComponent<Rigidbody2D>();
     GameOverText.SetActive(false);
     RestartButton.SetActive(false);
     animator = GetComponent<Animator>();
 }

 void FixedUpdate()
 {
     isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround );

     moveInput = CrossPlatformInputManager.GetAxis("Horizontal");
      rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
     if (moveInput == 0)
     {
         animator.SetBool("IsRunning", false);
     }
     else
     {
         animator.SetBool("IsRunning", true);
     }

     if (facingRight==false&& moveInput > 0)
     {
         flip();
     }
     if(facingRight==true && moveInput < 0)
     {
         flip();
     }
 }

 void Update()
 {
     if (isGrounded == true)
     {
         extraJumps = extraJumpValue;
         animator.SetBool("IsJumping", false);
     }
     else
     {
         animator.SetBool("IsJumping", true);
     }

     if (CrossPlatformInputManager.GetButtonDown("Jump") && extraJumps > 0)
     {
         rb.velocity = Vector2.up * jumpForce;
         extraJumps--;
         animator.SetTrigger("takeoff");

     }
     else if(CrossPlatformInputManager.GetButtonDown("Jump")&& extraJumps==0 && isGrounded==true)
     {
         rb.velocity = Vector2.up * jumpForce;
         animator.SetTrigger("takeoff");     
     }
     
 }
 void OnCollisionEnter2D(Collision2D col)
 {
     if (col.gameObject.tag.Equals("Enemy"))
     {
         GameOverText.SetActive(true);
         RestartButton.SetActive(true);
         gameObject.SetActive(false);
     }
 }


 void flip()
 {
     facingRight = !facingRight;
     Vector3 Scaler = transform.localScale;
     Scaler.x *= -1;
     transform.localScale = Scaler;
     
 }

} ,Im following Blackthornprods animation transition and 2d platformer tutorials (links: https://www.youtube.com/watch?v=FTxQKHG5WCA&t=812s https://www.youtube.com/watch?v=QGDeafTx5ug) and in it he uses this function to flip the character void flip() { facingRight = !facingRight; Vector3 Scaler = transform.localScale; Scaler.x *= -1; transform.localScale = Scaler;

 } 

I followed his steps one to one but my character wont flip

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by afraism · Feb 04, 2021 at 06:45 PM

Make sure that the gameObject to be flip don't have any animation key on scale in the animation. If this is the case, delete the keys related to the scale. If you do not understand what I mean, send a photo of the animation timeline.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by EvanCheddar · Feb 04, 2021 at 10:47 PM

Try flipping sprites with eulerAngles instead, something like this:

         transform.eulerAngles = new Vector3(0, 0, 0); //facing right
         facingLeft = false;

         transform.eulerAngles = new Vector3(0, 180, 0); //facing left
         facingLeft = true;
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RealFolk · Feb 05, 2021 at 02:28 AM 0
Share

This is the best way to do it from my experiences.

avatar image nicolaskhumukcham · Feb 05, 2021 at 03:14 PM 0
Share

Where do i implement this?

avatar image nicolaskhumukcham · Feb 05, 2021 at 03:19 PM 0
Share

Okay now when the characters sprite is flipping left but it doesnt flip to the right when turning right.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

129 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Sprite Fillup without using UI 1 Answer

How can I stop a glitch where my character transitions from left to right he snaps back? 0 Answers

Issue with Animating MultiPart 2D Character with RigidBodies 0 Answers

,Spawning snow or changing tilesets to snow as the player walks past them 0 Answers

How to sync animation if animation should be use with specially object 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges