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
-1
Question by DubstepDragon · Mar 30, 2014 at 02:26 PM · animationspriteaxisbool

Handling animations on sprites that involve axis...

I have a 2d sprite with four animation cycles, each 4 sprites long: "MoveUp", "MoveDown", "MoveLeft" and "MoveRight". Now, I am using GetAxis to allow my movement (top-down RPG style) to take place. I am testing this with my MoveUp animation, however the sprite seems to play it when it is moving up or down. Can I not limit this to when it is only moving upwards?

I have an Animator set up with the state WalkUp, that plays that animation when the parameter "Speed" is higher than "0.01".

Here is my script:

 using UnityEngine;
 using System.Collections;
 
 public class MoveMachine : MonoBehaviour {
     
     public float maxSpeed = 10f;
     
     Animator anim;
     
     // Use this for initialization
     void Start () {
         anim = GetComponent<Animator>();
     }
     
     // Update is called once per frame
     void Update () {
         float moveLR = Input.GetAxis ("Horizontal");
         float moveUD = Input.GetAxis ("Vertical");
         
         anim.SetFloat ("Speed", Mathf.Abs(moveUD));
         
         rigidbody2D.velocity = new Vector2 (moveUD * maxSpeed, rigidbody2D.velocity.y);
         rigidbody2D.velocity = new Vector2 (moveLR * maxSpeed, rigidbody2D.velocity.x);
     }
 }


I need urgent help with this issue as soon as possible please.

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 DubstepDragon · Mar 30, 2014 at 03:41 PM 0
Share

Pingpingping!

avatar image trololo · Apr 01, 2014 at 05:48 PM 0
Share

Just don't use $$anonymous$$athf.Abs()...

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by king_ · Mar 30, 2014 at 04:20 PM

what i meant was ,if you want to play the animation only once(like only when going up) ,so make a bool parameter to your jump animation like "public bool isJumping;' know that if a body is jumping then its y axis velocity will be positive, so check if the body's y axis velocity is positive or not.. if its positive then set the isJumping boolean property to true....


 if(rigidbody2d.velocity.y > 0.01f)
 {
    animator.setbool("isJumping",true);
 }



if you have any going down animation just know that y axis velocity will be negative while going down

Comment
Add comment · Show 6 · 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 DubstepDragon · Mar 30, 2014 at 05:45 PM 0
Share

I understand a little, but I still need more assistance. Can you perhaps rewrite the script for me, if it is not an issue? If not, then can you perhaps explain to me using extracts from my script? Oh and please format your code properly, it's a pain to try and understand unformatted code :/ But thanks!

avatar image DubstepDragon · Mar 30, 2014 at 08:21 PM 0
Share

Can you please respond as fast as possible?

Thanks in advance!

avatar image getyour411 · Mar 30, 2014 at 08:27 PM 0
Share

Really you should never ask someone to rewrite your script for you (and especially to do so in a snapsnap manner) that is not in the spirit of UA at all. If you didn't get what you need from that (where @king_ has answered your question with a specific code example), then your time, if you are in such a hurry, is going to be better spent reviewing the tutorials.

This is sounding more like 'my homework is due on $$anonymous$$onday'

avatar image DubstepDragon · Apr 01, 2014 at 05:15 PM 0
Share

I am very sorry for my attitude. I was indeed in a hurry, and was getting worried about this project, however I decided to postpone it until I understand 2D in Unity fully. However you may think of it, I am not a child, and my homework is not due on $$anonymous$$onday.

Again, I apologize for my lack of consistency, however @king_'s answer is not something I can understand easily. I have been working with C# for six years, and have been using Unity3D for two years. However, my issue was nothing in movement, it was the animation. I cannot handle this in bools, strictly because all my code relies on floats and axis, and would be a pain to rewrite. $$anonymous$$y movement is fine, all I need is separate animations for the two different values of the axis. Can someone assist me with that?

Oh and without further ado, let us avoid any comment drama. Please do not down-vote my question any further.

avatar image king_ · Apr 01, 2014 at 05:43 PM 1
Share

pixelnest.io http://www.raywenderlich.com/61532/unity-2d-tutorial-getting-started these two are so good tutorials for you right now ......... two days is enough for these tuts to complete...... if you finish these you'll know the in an outs of unity 2d animation

Show more comments

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

21 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

Related Questions

Custom Pivot Points in Sprite Editor 1 Answer

Scissor tool with 2d sprite 0 Answers

Animation not playing until i move character. 0 Answers

SpriteManager 2 1 Answer

Animation axis of UI element reversed (bug?) 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