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 Geexbee · Jun 20, 2013 at 03:55 PM · charactermodel importingimported

Movement script not working on imported model

My script so far is really basic, I wanted to get my character moving before moving onto the more interesting things.

My Code:

     var speed : float = 6.0;
     var jumpSpeed : float = 8.0;
     var gravity : float = 20.0;
     private var moveDirection : Vector3 = Vector3.zero;
     
     function Update () 
     {
         var controller : CharacterController = GetComponent(CharacterController);
         if(controller.isGrounded)
         {
             moveDirection = Vector3(Input.GetAxis( "Horizontal" ), 0, Input.GetAxis( "Vertical" ));
             moveDirection = transform.TransformDirection(moveDirection);
             moveDirection *= speed;
             
             if(Input.GetButton ( "Jump" ))
             {
                 moveDirection.y = jumpSpeed;
             }
          }
          
          moveDirection.y -= gravity * Time.deltaTime;
          
          controller.Move(moveDirection * Time.deltaTime);
     }

The problem I'm having is that, while this code works on spheres and anything else I attach it too (as long as it has a CharacterController) But it doesn't seem to work on my imported model?

The model I've imported I created in 3DS Max Design and imported it as an .FBX file. It's in two separate parts, a 'body' and a 'head' and there both parented under 'Character Full'.

I've been putting the script on Character Full and it does nothing, so tried putting it on just the 'body' and it started rolling around and going who knows where, without the head. Tried putting the script on all three parts as well, also didn't work out.

Any help would be appreciated, sorry if this question has been asked before I wasn't sure what to search for!

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 oliver-jones · Jun 20, 2013 at 04:06 PM

You need to make sure you have the correct attributes applied to your important object, such as the CharacterController. Try putting the 'body', and 'head' into an 'empty', then placing this script onto that empty as well as the character controller.

Also, try adding a Rigidbody

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 OmarAlhaddad · Jun 20, 2013 at 04:06 PM

This script needs to have a CharacterController component attached to the same object, you could easily add one on your imported model, the same place where you put this script.

Also i would advise moving this line:

 var controller : CharacterController = GetComponent(CharacterController);

..to your Awake() Method, as you only need to get the CharacterController once (bad for performance to get it and assign it every frame & unnecessary in this case), but to that you have to declare (var controller : CharacterController) outside .

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 Geexbee · Jun 20, 2013 at 05:53 PM

Thanks for the fast response guys!

I've tried putting 'body' and 'head' into a new empty with the same result, no movement at all. Adding a rigidbody just makes my character fall through the floor, or if i turn gravity off it just hovers in place.

I'll try your suggestions again, gotta be a simple problem somewhere.

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

16 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

Related Questions

Multiple Cars not working 1 Answer

When I look down and move forward, I fly upwards 0 Answers

I have a problem with my parkour C# script on final lines 0 Answers

How do i make the game start so that the character is already running? 1 Answer

Can Someone help me with a script? (2D) 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