• 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 Piesk · Feb 07, 2014 at 06:23 PM · character controller

moving a character controller

I Am trying to make an object follow a path with realistic movement. The controller.simplemove just doesn't seem to be doing anything. For a little bit of extra background info:

Thanks to Maui M it no longer simply drops off into -y, but it still does not move as needed.

The object in question is a "fleet" that contains sub objects "squads", these squad objects contain ship objects. These ship objects have their own colliders and character controllers (as during combat the need to move independently from the fleet). I saw mention that one person had a similar problem where his object was colliding with it's own face and so wouldn't move, however the sub objects are disabled at this time so this can't be the problem. Thanks for any help in advance.

 void MoveTowards(Vector3 position)
     {
 
         //movement direction
         Vector3 dir = position - myTransform.position;
 
         // Rotate towards the target
         myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
                                                 Quaternion.LookRotation(dir), rotationSpeed * Time.deltaTime);
 
         Debug.DrawRay(myTransform.position,myTransform.forward);
 
         Vector3 forwardDir = myTransform.forward;
         forwardDir = forwardDir * speed;
         float speedModifier = Vector3.Dot(dir.normalized, myTransform.forward);
         forwardDir *= speedModifier;
         if (speedModifier > 0.95f)
         {
             controller.SimpleMove(forwardDir);  <-------------- command in question
             //if (!animation["walk"].enabled)
                 //animation.CrossFade("walk");
         }
         //else if (!animation["idle"].enabled)
         //    animation.CrossFade("idle");
     }
Comment
Add comment · Show 1
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 Piesk · Feb 07, 2014 at 06:26 PM 0
Share

just realized the gravity thing can't be the issue, it only moves in the Y when if(speed$$anonymous$$odifier > 0.95f) is true.

2 Replies

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

Answer by Maui-M · Feb 07, 2014 at 08:40 PM

It is affected by gravity.

simpleMove - Velocity along the y-axis is ignored. Speed is in meters/s. Gravity is automatically applied. Returns if the character is grounded. It is recommended that you make only one call to Move or SimpleMove per frame.

 Physics.gravity = new Vector3(0, 0, 0);


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 Piesk · Feb 08, 2014 at 09:53 AM 0
Share

Thank you very much, i've read that again and again but those 4 words are the only 4 i don't remember seeing... skim reading fail i guess. I will try this.

avatar image Piesk · Feb 08, 2014 at 10:11 AM 0
Share

It worked thank you! but the problem that it is not actually moving in the forward direction still persist, is there something else i need to apply to get the character controller to work with simplemove? Thank you for your help.

avatar image Maui-M · Feb 09, 2014 at 05:30 PM 0
Share

Hard to tell what the difference between speed and speed modifiers are but I think if you replace the following lines you should get closer to what you are looking for:

 Vector3 forwardDir = myTransform.forward;
 forwardDir = forwardDir * speed;
 float speed$$anonymous$$odifier = Vector3.Dot(dir.normalized, myTransform.forward);
 forwardDir *= speed$$anonymous$$odifier;

With:

 Vector3 forwardDir = dir.normalized * speed$$anonymous$$odifier; // speed$$anonymous$$odifier or speed
avatar image Piesk · Feb 10, 2014 at 09:47 AM 0
Share

the forwardDir vector is computed just fine, it comes out like intended. but Simplemove(forwardDir) doesn't do anything (i have run debug on it and forwardDir is calculated correctly co$$anonymous$$g out as (-0.4,0,0.2) or something like that).

avatar image Piesk · Feb 10, 2014 at 10:47 AM 0
Share

i've discovered the problem, simplemove requires gravity, going to try move ins$$anonymous$$d as it should do what's needed.

avatar image
0

Answer by Piesk · Feb 10, 2014 at 11:03 AM

Problem solved =).

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

OnControllerColliderHit, hit.normal direction is unstable 0 Answers

Player stalls on consecutive steps 0 Answers

Orientation of character controller relative to ground normal? 0 Answers

Controlling an animated character? 1 Answer

CharacterController vertical velocity is flickering on ground 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