Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 LoKo6264 · Jun 08, 2016 at 02:08 PM · animationanimatoranimator controlleravatarpreview

Placing my own animation idle&move to player

Hi there,

I made my first animations for idle and move, I want to put them to my player of course in sense when he is not moving - play animation for idle, when press "W/S/A/D" - play animation for move. Earlier I was using tutorial from Unity channel and now I wrote exactly that same script for it but it doesn't work.

Here it is:

 using UnityEngine;
 
 public class WalkingKyle : MonoBehaviour
 {
     public float speed = 6f;
     Vector3 movement;
     Animator anim;
     Rigidbody playerRigidbody;
     int floorMask;
     float camRayLenght = 100f;
 
     void Awake()
     {
         floorMask = LayerMask.GetMask("Floor");
         anim = GetComponent<Animator>();
         playerRigidbody = GetComponent<Rigidbody>();
     }
 
     void FixedUpdate()
     {
         float h = Input.GetAxisRaw("Horizontal");
         float v = Input.GetAxisRaw("Vertical");
 
         Move(h, v);
         Turning();
         Animating(h, v);
     }
 
     void Move(float h, float v)
     {
         movement.Set(h, 0f, v);
         movement = movement.normalized * speed * Time.deltaTime;
         playerRigidbody.MovePosition(transform.position + movement);
     }
 
     void Turning()
     {
         Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit floorHit;
 
         if (Physics.Raycast(camRay, out floorHit, camRayLenght, floorMask))
         {
             Vector3 playerToMouse = floorHit.point - transform.position;
             playerToMouse.y = 0f;
 
             Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
             playerRigidbody.MoveRotation(newRotation);
         }
 
 
     }
 
     void Animating(float h, float v)
     {
         bool walking = h != 0f || v != 0f;
         anim.SetBool("IsWalking", walking);
     }
 }
 

I noticed I don't have preview view for these animation and maybe problem is in here? I don't know how to do previw view, I looked for on youtube creating animations tutorial but nothing about it I saw. Also, I noticed I don't have avatar in animator controller of my player. As previously - I don't know how to do it and if problem is inside this or not.

Can anyone help?

Edit

I've just seen I don't have motion put to the states. I tried add my animations to them but I can't with both. Does someone know why I'm unable to do that?

Comment
Add comment · Show 5
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 EpiFouloux · Jun 08, 2016 at 04:19 PM 0
Share

$$anonymous$$any problems here:

You shouldn't handle your input in a FixedUpdate() but in Update(), so you need to split your code in two scripts, one for input (Update) one for physics (FixedUpdate). $$anonymous$$oreover If you use your FixedUpdate() correctly, your movement variable should depend on Time.fixedDeltaTime and not Time.deltaTime

But that won't solve your animation problem.

I think the Animator isn't set properly, or maybe you just forgot to call anim.Play() https://docs.unity3d.com/ScriptReference/Animator.Play.html

But I'm not really good on animations..

avatar image LoKo6264 EpiFouloux · Jun 08, 2016 at 05:09 PM 0
Share

Heh, thanks for correct :) As I said I was doing this from Unity $$anonymous$$m tutorials and they did it like this so idk :P

Yeah, I didn't call anim.Play()but in previous project, this one from Unity $$anonymous$$m, wasn't call it and every animation worked good. But I think I know where is problem. In my states of idle and move, I noticed there is no motion put to them. I tried to put there my animations but I couldn't. Do you know why?

avatar image EpiFouloux LoKo6264 · Jun 08, 2016 at 06:53 PM 0
Share

$$anonymous$$aybe you should put a screenshot, I have no idea right now, It can be anything

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

85 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

Related Questions

Applying permanent mask to player animators walk 0 Answers

Why isn't my animation looping? 3 Answers

Avatar mask affects on unselected bones 1 Answer

Animator Check the end of an animation 1 Answer

I can't see or access a state in the Animation Controler 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