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 alarm656 · Jan 24, 2014 at 12:54 AM · mobilephone

Help with mobile character animations

hello all, I'm new in Unity. I have a character which controls by two joysticks. My character model has no his own animation and I put him animation from another model. Mecanim, humanoid etc. First default "Idle" animation works fine but I can't animate walk animation. it's moves and animates if I press W,S,A and D buttons. if I test it in my iPhone the character model only moves not animates. I have used this script: using UnityEngine; using System.Collections;

public class PlayerMovevment : MonoBehaviour {

 // This component is only enabled for "my player" (i.e. the character belonging to the local client machine).

 // Remote players figures will be moved by a NetworkCharacter, which is also responsible for sending "my player's"
 // location to other computers.
 
 public float speed = 10f;        // The speed at which I run
 public float jumpSpeed = 6f;    // How much power we put into our jump. Change this to jump higher.
 
 // Booking variables
 Vector3 direction = Vector3.zero;    // forward/back & left/right
 float   verticalVelocity = 0;        // up/down
 
 CharacterController cc;
 Animator anim;
 
 // Use this for initialization
 void Start () {
     cc = GetComponent<CharacterController>();
     anim = GetComponent<Animator>();
 }
 
 // Update is called once per frame
 void Update () {
     
     // WASD forward/back & left/right movement is stored in "direction"
     direction = transform.rotation * new Vector3( Input.GetAxis("Horizontal") , 0, Input.GetAxis("Vertical") );
     
     // This ensures that we don't move faster going diagonally
     if(direction.magnitude > 1f) {
         direction = direction.normalized;
     }
     
     // Set our animation "Speed" parameter. This will move us from "idle" to "run" animations,
     // but we could also use this to blend between "walk" and "run" as well.
     anim.SetFloat("Speed", direction.magnitude);
     
     // If we're on the ground and the player wants to jump, set
     // verticalVelocity to a positive number.
     // If you want double-jumping, you'll want some extra code
     // here instead of just checking "cc.isGrounded".
     if(cc.isGrounded && Input.GetButton("Jump")) {
         verticalVelocity = jumpSpeed;
     }
 }
 
 // FixedUpdate is called once per physics loop
 // Do all MOVEMENT and other physics stuff here.
 void FixedUpdate () {
     
     // "direction" is the desired movement direction, based on our player's input
     Vector3 dist = direction * speed * Time.deltaTime;
     
     if(cc.isGrounded && verticalVelocity < 0) {
         // We are currently on the ground and vertical velocity is
         // not positive (i.e. we are not starting a jump).
         
         // Ensure that we aren't playing the jumping animation
         anim.SetBool("Jumping", false);
         
         // Set our vertical velocity to *almost* zero. This ensures that:
         //   a) We don't start falling at warp speed if we fall off a cliff (by being close to zero)
         //   b) cc.isGrounded returns true every frame (by still being slightly negative, as opposed to zero)
         verticalVelocity = Physics.gravity.y * Time.deltaTime;
     }
     else {
         // We are either not grounded, or we have a positive verticalVelocity (i.e. we ARE starting a jump)
         
         // To make sure we don't go into the jump animation while walking down a slope, make sure that
         // verticalVelocity is above some arbitrary threshold before triggering the animation.
         // 75% of "jumpSpeed" seems like a good safe number, but could be a standalone public variable too.
         //
         // Another option would be to do a raycast down and start the jump/fall animation whenever we were
         // more than ___ distance above the ground.
         if(Mathf.Abs(verticalVelocity) > jumpSpeed*0.75f) {
             anim.SetBool("Jumping", true);
         }
         
         // Apply gravity.
         verticalVelocity += Physics.gravity.y * Time.deltaTime;
     }
     
     // Add our verticalVelocity to our actual movement for this frame
     dist.y = verticalVelocity * Time.deltaTime;
     
     // Apply the movement to our character controller (which handles collisions for us)
     cc.Move( dist );
 }

}

How to animate character with joysticks? Thank you in advance))alt text

fps.png (485.9 kB)
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 getyour411 · Jan 24, 2014 at 01:14 AM 0
Share

This seems to be the only thing setting "speed" and the Anim state:

 // WASD forward/back & left/right movement is stored in "direction"
 direction = transform.rotation * new Vector3( Input.GetAxis("Horizontal") , 0, Input.GetAxis("Vertical") );

Are your "joysticks" using these Input.GetAxis - is this script the only movement control on player?

avatar image alarm656 · Jan 24, 2014 at 03:02 AM 0
Share

Thank you getyour411 reply. $$anonymous$$y josticks aren't uses this script. I put this script into Player(model character)

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

18 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

Related Questions

Azure Mobile Services Authentication with Facebook always gives Unauthorized error 0 Answers

How to freeze z-axis movement? 3 Answers

I am creating a Co-op, puzzle game, multiplayer app. Lan help needed. 0 Answers

How to stop collision at specific distance? 2 Answers

SceneManager.LoadSceneAsync loaded scene takes too long to open 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