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
1
Question by wnfakind · Mar 26, 2017 at 12:04 AM · movementplayermovement scriptplayer movement

Moving simultaneously with UP LEFT, W D using GetAxisRaw. Rotating localScale to flip animation

Hi, this is currently my script. I'm able to move my guy in any direction with the animation going from the "Walk" to "Idle" state. I feel this GetAxisRaw might cause alot of problems when it comes to adding more animations to move him up facing up or down facing down.. in the future. I can't for the life of me figure out how to flip its local scale and continue the walk cycle after moving right to left so that the animation is facing in the opposing direction.

I'm trying to get the character movement of Stardew valley. I have three frames at the moment, Idle and two walk animations, and seems to be working my my favour so far but it looks and feels like a mess.

Here is the script:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
     
     public float moveSpeed;
     private Animator anim;
 
 
     void Awake() {
         anim = GetComponent<Animator> ();
 }
 
     void Start () {
     
 }
 
 // Update is called once per frame
         void Update () {
         if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f )
             
         {
             transform.Translate (new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f ));
             anim.SetBool ("Walk", true);
                             
         } else if (Input.GetAxisRaw("Horizontal") == 0.0f || Input.GetAxisRaw("Horizontal") == -0.0f )
               anim.SetBool ("Walk", false);
 
         if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
         {
             transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f));
             anim.SetBool ("Walk", true);
             
         }
     }
     
 }

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 wnfakind · Mar 26, 2017 at 01:13 AM

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
     
     public Vector3 theScale;
     public float moveSpeed;
     private Animator anim;
 
 
     void Awake() {
         anim = GetComponent<Animator> ();
 }
 
     void Start () {
 
 }
 
 // Update is called once per frame
         void Update () {
         if (Input.GetAxisRaw("Horizontal") > 0.5f)
             
         {
             Vector3 temp = transform.localScale;
             temp.x = 0.3f;
             transform.localScale = temp;
         
             transform.Translate (new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f ));
             anim.SetBool ("Walk", true);                
             
         } else if (Input.GetAxisRaw("Horizontal") == 0.0f) 
             anim.SetBool ("Walk", false);
             
         if (Input.GetAxisRaw("Horizontal") < -0.5f)
             
         {
             Vector3 temp = transform.localScale;
             temp.x = -0.3f;
             transform.localScale = temp;
                 
             transform.Translate (new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
             anim.SetBool ("Walk", true);                
             
         } else if (Input.GetAxisRaw("Horizontal") == 0.0f) 
             anim.SetBool ("Walk", false);
     }
 }

EVERYTHING HORIZONTAL WORKS AS I WANT Unable to copy and paste and change horizontal to vertical values to make it work! I believe this is a mess, but it's slowly work!

EDIT: While copy and pasting code and changing those values, the animation doesn't work anymore horizontally but does move. Vertical keys now move him Horizontal with the animations working.. it broke it.

I'm now trying to split each direction up so I can add separate functions with them. This is going well so far horizontally but when I copy the code and paste it and change Horizontal to Vertical everything goes down the drain. I want to be able to control each one seperatly using GetAxisRaw.

See I figured I'd be able to copy what I have paste it and change everything to vertical but this has no effect besides everything not working. I don't think I actually understand the values floats ect and how they work with the (Input.GetAxisRaw("Horizontal") > 0.5f) <-----

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 DryreL · Mar 13, 2021 at 06:45 PM

I want to know this as well

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

123 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

Related Questions

How to move 3 players at the same time in V form,How to move 3 characters in the same time in V form 0 Answers

Reduce Player Movement in Air 0 Answers

Player only moves when the key is pressed, not when it's held. 0 Answers

Dash Movement Platformer 0 Answers

Object rotates when moving sideways 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