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 /
avatar image
0
Question by rooster2 · Nov 08, 2016 at 03:31 PM · c#animator

setting up animations

have animations i have done it before but i cant remeber how i was wondering if something could look at my code and see how i have failed when i try to move to activate the animation it doesnt move and when i comment it out and put it back to normal it moves

using UnityEngine;

using System.Collections;

public class Movement : MonoBehaviour {

 public float Speed = 5.0f;
 Animator anim;
 public bool Ismoving;

 // Use this for initialization
 void Start () {
     anim = GetComponent<Animator> ();
 }

 // Update is called once per frame
 public void Update () {
         var x = Input.GetAxis ("Horizontal") * Speed * Time.deltaTime;
         var z = Input.GetAxis ("Vertical") * Speed * Time.deltaTime;
         transform.Translate (x, 0, z);
         Ismoving = true;
     anim.SetFloat ("Speed", Speed);
     if(Input.GetAxis("Horizontal") && Input.GetAxis("Vertical") == null){
         Ismoving = false;
         anim.SetFloat ("Speed", 0);
     }
 }

}

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 Zodiarc · Nov 08, 2016 at 03:35 PM 0
Share

How are we supposed to know how you failed? What is happening? What should happen?

avatar image rooster2 Zodiarc · Nov 09, 2016 at 10:25 AM 0
Share

sorry i forgot lol i was making this question mid lecture basically when i try to apply animations it cancls the movement

1 Reply

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

Answer by sh_code · Nov 09, 2016 at 12:29 PM

  1. afaik, Input.GetAxis never returns null (unless maybe when said axis doesn't exist at all). When the axes get no input, they should be zero. so the condition is wrong and to correct it, you need to change it to

if(Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0)

  1. secondly, other than that, code doesn't seem to have anything outright wrong with it, so I'd check the Mecanim state machine, animation transition settings and conditions, as these errors are usually either there, or arise from incorrect interaction of code and the state machine settings.

  2. Nothing more can be inferred from the sparse info you've provided.

Comment
Add comment · Show 2 · 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 sh_code · Nov 10, 2016 at 01:44 AM 0
Share

thirdly, @rooster2, it would be nice of you to specify what was the error, because I doubt my first point was the only, or the main part of the issue. you explaining what the issue really was after fixing it will not only provide the people who tried to answer a closure, and the feeling that motivates them to help, but will also provide a possible ready-made answer for others after you facing the same/similar issue ;)

avatar image rooster2 sh_code · Nov 11, 2016 at 11:10 PM 0
Share

it was our frst point and i cant remeber what it was but something about not being able to do something with floats and inputs i was bored in a lecture so i decided id do some on my game but got stuck and you help origato

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Play Animation with int (ammo count) 0 Answers

Can't Set Animator Boolean Parameter C# 1 Answer

Why isn't the animator getting my values? 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