Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Jray4 · Sep 11, 2016 at 05:18 PM · animationmovementcharactercontrollerinput.getaxis

8-way movement (diagonal) idle issues

I am working on animations for 8-way movement for my characters. It was simple enough to get 4-way movement and idle animations set. I was also able to setup the other 4 directions and their idle animations. My issue is that when I am moving diagonally (e.g. A+W) and stop moving, the character does not stay facing diagonally, it reverts to left or up (A or W). The only way I can get it to idle in a diagonal direction is to try over and over again to release the keys at exactly the same time (which is not easy). I'm not sure if adding input lag will help with this or not. Does anyone have any advice? Any help is appreciated!

Comment
Add comment · Show 1
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 RustyCrow · Sep 11, 2016 at 07:44 PM 0
Share

$$anonymous$$aybe remember(bool) the direction your walking ins$$anonymous$$d of the button presses. This might be a very unnecessary expense. Just my 2 cents :P.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tkati · Sep 12, 2016 at 01:03 AM

Why not map with 8 keys and 8 states? or 8 states where one of the keys sends the character "forward" and the state dictating which x/y change that would be?

   using UnityEngine;
     using System.Collections;
     
     public abstract class ScrMovement : MonoBehaviour {
     
         public float movementSpeed;
         public float baseMovesPerTurn;
         public float movementPts;
         public static float xDistanceRowToNextRow = 0.5f;
         public static float yDistanceColTonNextCol = 1.0f;
     
         protected Animator animtr;
         protected int faceDirection;
         protected bool isTurning;
         protected bool isAttacking;
         protected bool isWalking;
     
         // Use this for initialization
         protected virtual void Start () {
             animtr = GetComponent<Animator>();
         }
         
         // Update is called once per frame
         void Update () {
         
         }
     
         public virtual void TurnObjCheck() { }
         public virtual void MoveForward() { }
         public virtual void UpdateFacingState(int change) { }
     }
     using UnityEngine;
     using System.Collections;
     
     public class ScrPlayer : ScrMovement {
         private Rigidbody2D rb2;
     
         // Use this for initialization
         protected override void Start () {
             base.Start();
             rb2 = GetComponent<Rigidbody2D>();
             faceDirection = 0;
             isAttacking = false;
             isTurning = false;
             isWalking = false;
             SetAnimator();
             
         }
         
         // Update is called once per frame
         void Update () {
         
         }
     
         void FixedUpdate()
         {
             TurnObjCheck();
             MoveForward();
         }
     
         public override void TurnObjCheck()
         {
             if (!isWalking && !isAttacking)
             {
                 if (Input.GetKeyDown("q"))
                 {
                     isTurning = true;
                     UpdateFacingState(-1);
                     SetAnimator();
                     animtr.SetTrigger("TurnCounterClockwise");
                 }
                 else if (Input.GetKeyDown("e"))
                 {
                     isTurning = true;
                     UpdateFacingState(1);
                     SetAnimator();
                     animtr.SetTrigger("TurnClockwise");
                 }
                 isTurning = false;
             }
         }
     
         public override void MoveForward()
         {
             if (Input.GetKeyDown("w") && !isTurning && !isAttacking)
             {
                 isWalking = true;
                 SetAnimator();
                 switch (faceDirection)
                 {
                     case 0: animtr.SetTrigger("WalkS");
                         rb2.transform.Translate(new Vector3( movementSpeed * Time.deltaTime, 0.0f));
                         break;
                     case 1: animtr.SetTrigger("WalkSW"); break;
                     case 2: animtr.SetTrigger("WalkW"); break;
                     case 3: animtr.SetTrigger("WalkNW"); break;
                     case 4: animtr.SetTrigger("WalkN"); break;
                     case 5: animtr.SetTrigger("WalkNE"); break;
                     case 6: animtr.SetTrigger("WalkE"); break;
                     case 7: animtr.SetTrigger("WalkSE"); break;
                     default: break ;
                 };
                 isWalking = false;
                 SetAnimator();
             }
         }
     
         public override void UpdateFacingState(int change)
         {
             faceDirection += change;
             if (faceDirection < 0)
                 faceDirection = 7;
             else if (faceDirection >= 8)
                 faceDirection = 0;
         }
     
         void SetAnimator()
         {
             animtr.SetBool("Attacking", isAttacking);
             animtr.SetBool("Turning", isTurning);
             animtr.SetBool("Walking", isWalking);
             animtr.SetInteger("FaceDir", faceDirection);
         }
     }


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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make player rotate 180° and run that direction with mecanim + vice versa? 1 Answer

Character Animation Shake (MakeHuman + Unity MoCap Animations) 0 Answers

Keep position of CharacterController relative to rotating platform 0 Answers

Animation for each movement direction 0 Answers

Vector3.Distance returning offset values due to down force interference. 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