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 dreal1220 · Dec 27, 2011 at 11:58 AM · animationcharactercontroller3dsmaxboneskinned-mesh

Animation issues With Game Character

Wondering if anyone can help me with this one...I have exported a skinned mesh character into unity and when i play his animations, he shrinks and snaps back to 0,0,0 position. So i put an empty game object on him so it can play its animation where i want it to play. That works and all but how do i get the character controller to work on a parented Game Character? I put the character controller on the game character and nothing happens. I have terrain collider in position for the game character to fall on and nothing happens. Can anyone please help me???

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

1 Reply

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

Answer by AmunTech · Dec 28, 2011 at 03:33 AM

I think what you want to do is to add the character controller on the empty gameobject and create a variable that holds the character mesh. After this create a function that play the animations, something like this:

//This is the character var Character : GameObject;

 // In the update function add the AnimateCharacter function 
 function Update(){

 AnimateCharacter();
 }


 //This is the function that crossfade the animations
 function AnimateCharacter(){
     if (Input.GetAxis("Vertical") || Input.GetAxis("Horizontal")){
     Character.animation.CrossFade("walk");

 }else{
     Character.animation.CrossFade("idle");
     }
 }

EDIT private var motor : CharacterMotor; var Character : GameObject;

// Use this for initialization function Awake () { Character.animation.wrapMode = WrapMode.Loop; motor = GetComponent(CharacterMotor); }

// Update is called once per frame function Update () { // Get the input vector from kayboard or analog stick var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

 if (directionVector != Vector3.zero) {
    // Get the length of the directon vector and then normalize it
    // Dividing by the length is cheaper than normalizing when we already have the length anyway
    var directionLength = directionVector.magnitude;
    directionVector = directionVector / directionLength;

    // Make sure the length is no bigger than 1
    directionLength = Mathf.Min(1, directionLength);

    // Make the input vector more sensitive towards the extremes and less sensitive in the middle
    // This makes it easier to control slow speeds when using analog sticks
    directionLength = directionLength * directionLength;

    // Multiply the normalized direction vector by the modified length
    directionVector = directionVector * directionLength;
 }

 // Apply the direction to the CharacterMotor
 motor.inputMoveDirection = transform.rotation * directionVector;
 motor.inputJump = Input.GetButton("Jump");


 AnimateCharacter(); 

}

// Require a character controller to be attached to the same game object @script RequireComponent (CharacterMotor) @script AddComponentMenu ("Character/FPS Input Controller")

function AnimateCharacter(){ if (Input.GetAxis("Vertical") && Input.GetAxis("Horizontal")){ Character.animation.CrossFade("Run");

}else{ Character.animation.CrossFade("idle");

 }

}

Comment
Add comment · Show 5 · 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 dreal1220 · Dec 29, 2011 at 08:08 PM 0
Share

private var moveDirection : Vector3 = Vector3.zero; private var speed : float = 6.0; var footballPlayer : CharacterController; var playerObject : GameObject; function Start(){

footballPlayer = GetComponent(CharacterController); playerObject.animation.wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Loop; } function Update () {

if(Input.GetAxis("Vertical") || Input.GetAxis("Horizontal") ){ playerObject.animation["Run"].speed = 1;

         moveDirection =  transform.TransformDirection(moveDirection);
         moveDirection *= speed; 
             playerObject.animation.CrossFade("Run");
             playerObject.animation["Run"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Loop;
             footballPlayer.$$anonymous$$ove(moveDirection * Time.deltaTime);
                             
         }else{
     playerObject.animation.CrossFade("idle");
         }

}

This is the code that im using and i put this on the parent object. but it still doesn't make the character controller respond on the parent object. I really don't know what to do from here.

avatar image dreal1220 · Dec 29, 2011 at 10:00 PM 0
Share

Try to recreate it yourself and see what exactly i am talking about.

avatar image AmunTech · Dec 30, 2011 at 03:34 PM 0
Share

take a look at the edited script, "the character mesh have to be inside of the empty gameobject". I tested it so i can confirm that this works fine.

avatar image dreal1220 · Dec 31, 2011 at 10:26 AM 0
Share

Thanks a lot it worked!

avatar image AmunTech · Dec 31, 2011 at 11:12 AM 0
Share

i'm happy to be helpful, don't forget to set the answer as correct and happy new year!

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

What is the best animaiton program? 1 Answer

Bone animation: unwanted objects with key frames 1 Answer

Skinned Mesh Renderer and Mesh filter appearing on a bone 3 Answers

Dynamically instantiated skinned mesh not playing animations 4 Answers

Character controller problem? 2 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