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 /
This question was closed Mar 03, 2014 at 04:46 AM by serenefox for the following reason:

Figured it out

avatar image
0
Question by serenefox · Mar 02, 2014 at 11:26 PM · 2dmecanimflipinput.getaxislocalscale

2D Input.GetAxis not recognized when local scale is flipped

I am trying to make a running attack and a stationary attack for my player character, It works when I am facing to the right but when I flip my character to the left when moving left it doesn't recognize the Input.GetAxis float value which doesn't make the isRunning variable true. I want my character to preform "attackOne" when stationary and "attackTwo" when running in either direction(left or right).

This is the my code can anyone help me out or know why it is happening?:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
     
 
     public float maxSpeed = 18.0f;
     public bool facingRight = true;
     public bool isGrounded = false;
     public Transform groundCheck;
     public float groundRadius = 0.2f;
     public LayerMask whatIsGround;
     public float jumpForce = 1300.0f;
     public bool isDead = false;
     public Collider2D attackTrigger;
     public Collider2D attackTriggerTwo;
     private bool attackOneComplete = true;
     private bool attackTwoComplete = true;
     private bool isRunning = false;
     private Animator anim;
     
     void Start () 
     {
         anim = GetComponent<Animator>();
         isDead = false;
     }
     
     void FixedUpdate () 
     {
         
         if(isDead == false)
         {
             isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
             anim.SetBool("Ground", isGrounded);
 
             float move = Input.GetAxis("Horizontal");
             anim.SetFloat("Speed", Mathf.Abs(move));
             rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
 
             if(move > 0.01f)
             {
                 isRunning = true;
             }
             else if(move < 0.01f)
             {
                 isRunning = false;
             }
 
             if(move > 0 && !facingRight)
             {
                 FlipFacing();
             }
             else if(move <0 && facingRight)
             {
                 FlipFacing();    
             }
         }
         
     }
     
     void Update()
     {
         if(isGrounded && Input.GetButtonDown("Jump") && isDead == false)
         {
             anim.SetBool("Ground", false);
             rigidbody2D.AddForce(new Vector2(0, jumpForce));
         }
 
         if(Input.GetButtonDown("Fire1") && attackOneComplete == true && isRunning == false && isDead == false)
         {
             StartCoroutine("AttackModeOne");
         }
 
         if(Input.GetButtonDown("Fire1") && attackTwoComplete == true && isRunning == true && isDead == false)
         {
             StartCoroutine("AttackModeTwo");
         }
 
 
     }
     
     void FlipFacing()
     {
         facingRight = !facingRight;
         Vector3 charScale = transform.localScale;
         charScale.x *= -1;
         transform.localScale = charScale;
     }
 
     IEnumerator AttackModeOne()
     {
         attackOneComplete = false;
         anim.SetTrigger("Attack");
         yield return new WaitForSeconds(0.2f);
         attackTrigger.enabled = true;
         attackOneComplete = true;
         yield return new WaitForSeconds(0.1f);
         attackTrigger.enabled = false;
     }
 
     IEnumerator AttackModeTwo()
     {
         attackTwoComplete = false;
         anim.SetTrigger("Attack2");
         yield return new WaitForSeconds(0.2f);
         attackTriggerTwo.enabled = true;
         yield return new WaitForSeconds(0.7f);
         attackTwoComplete = true;
         attackTriggerTwo.enabled = false;
     }
 }
Comment
Add comment · Show 2
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 robertbu · Mar 03, 2014 at 04:33 AM 0
Share

Not sure if this help or not with your issue, but the shader used for Sprites is two-sided. So you can flip your character by rotating 180 degrees on the 'y' rather than setting the local scale to a negative value (assu$$anonymous$$g your anchor is in the middle).

avatar image serenefox · Mar 03, 2014 at 04:45 AM 0
Share

Thanks for the reply. Yeah I have that on my enemy characters but my player is setup to where if I did that I would mess up the sprite. But I did find a way around it by adding:

 if(rigidbody2D.velocity.magnitude > 0)
 {
  isRunning = true
 }

and so on... So I will close the question.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

20 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

Related Questions

My sprite is teleporting when I change my scale to -1 to flip it 1 Answer

Flipped objects Rotation issues 1 Answer

flip scale of a tank but turret aim wrong 0 Answers

2D Animation does not start 1 Answer

rigidBody2d.rotation only updating if rigidbody is moving. 1 Answer


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