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
0
Question by circusstudios · Aug 01, 2014 at 08:13 PM · movementcharactercontroller

How do I get the speed float to work in Unity?

I am new to unity and I am starting out by making a simple level in which you walk around in in first and third person. I am trying to animate the characters idle and walking am having trouble. Everything works fine including the transition from idle to walk until I change the exit time float to a speed float. I added the speed float and ordered it to transition from idle to walk if the speed is greater than 0.1. When I do that and play the walking animation never happens and I glide around in the idle animation. Does anyone know what I can change to fix this problem?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by malu · Aug 01, 2014 at 09:32 PM

You have to forward the current speed/velocity to your Animator speed value. Get the Animator on Start or set a reference to the public member.

 public Animator mAnimator;
 Rigidbody mBody;
 
 void Start()
 {
     mBody = GetComponent<Rigidbody>();
 }
 
 void Update()
 {
     mAnimator.SetFloat("MySpeed", mBody.velocity.magnitude);
 }
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 Adamcbrz · Aug 01, 2014 at 09:03 PM

I assume the problem is that you are not setting the speed value anywhere. A simple way to do that would be to code a script that access the animator's speed variable.

 GetComponent<Animator>().SetFloat("Speed", 1);
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 circusstudios · Aug 01, 2014 at 09:32 PM 0
Share

I wrote my own player movement script and set the float speed to 10f . Is that not the same thing?

avatar image Adamcbrz · Aug 01, 2014 at 09:35 PM 0
Share

not if you don't tell the animator.

avatar image
0

Answer by circusstudios · Aug 01, 2014 at 10:00 PM

using UnityEngine; using System.Collections;

public class PlayerMovement : MonoBehaviour {

 float speed = 10f;
 Vector3 direction = Vector3.zero;

 CharacterController cc;

 // Use this for initialization
 void Start () {
     cc = GetComponent<CharacterController>();
 }
 
 // Update is called once per frame
 void Update () {
     direction = transform.rotation * new Vector3( Input.GetAxis ("Horizontal") , 0, Input.GetAxis ("Vertical") ).normalized;
 }

 void FixedUpdate () {
     cc.SimpleMove(direction * speed); 

 }

}

This is my player movement script. Can you edit my code to get it to do what you're saying?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I guarantee a CharacterController never leaves the ground? 2 Answers

FPC Moves itself 0 Answers

Charecter Controller like in Merry Bear game(Cube based game). 0 Answers

Stop animation when character controller hits walls 1 Answer

Character Controller - unknown rotation, flying 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