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 Magnomous · Jul 01, 2014 at 07:01 AM · c#charactercontrollersimplemove

CharacterController.SimpleMove() doesn't work

Hello guys,

I am working on "click to move" script to my game and everything in script works except line of code with SimpleMove(). Unity writes no error, it just does not move, even it rotates correctly. And yes, CharacterController is attached to Player gameobject and is assigned in the inspector. Here is the script:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(CharacterController))]
 public class CharacterMovement : MonoBehaviour {
 
     private Vector3 _targetPosition;    
 
     public float speed;
     public float rotationSpeed;
     public Camera mainCamera;
     public CharacterController controller;
 
     void Start () {
         
         _targetPosition = transform.position;
         speed = 2f;
         rotationSpeed = 4f;
     }
     
     void Update () {
 
         if(Input.GetKeyDown(KeyCode.Mouse1)) {
 
             Ray _ray;
             RaycastHit _hit;
   
             _ray = mainCamera.ScreenPointToRay(Input.mousePosition);
 
             if(Physics.Raycast(_ray, out _hit, 20) && _hit.collider.tag != "Player") {
 
                 _targetPosition = _hit.point;
             }
         }
         
         if(Vector3.Distance(transform.position, _targetPosition) < 0.1f) _targetPosition = transform.position;      
         
         Move();
     }
 
     private void Move() {
 
         if(transform.position != _targetPosition) {
     
             Quaternion lookPosition = Quaternion.LookRotation(_targetPosition - transform.position);
             lookPosition.x = 0;
             lookPosition.z = 0;
             transform.rotation = Quaternion.Slerp(transform.rotation, lookPosition, rotationSpeed * Time.deltaTime);
 
             controller.SimpleMove(transform.forward * speed);
         }
     }
 }
 
Comment
Add comment · Show 6
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 Kiwasi · Jul 01, 2014 at 07:34 AM 0
Share

No idea whats up.

Try a debug.log just before the call to simple move.

Try setting speed really high.

avatar image Magnomous · Jul 01, 2014 at 08:17 AM 0
Share

I setted speed to 1 000 and still Player is not moving. I added Debug.Log before and after Simple$$anonymous$$ove and both of them appeared in the console...Could this be a Unity bug or something?

avatar image HarshadK · Jul 01, 2014 at 08:20 AM 3
Share

It might be that your character is stuck in the ground or blocked by any invisible collider? Try moving it above the ground and to a new position.

Also one thing to note is that Simple$$anonymous$$ove() documentation page says that:

Gravity is automatically applied. Returns if the character is grounded.

So also check if your character is grounded properly.

avatar image Kiwasi · Jul 01, 2014 at 08:21 AM 1
Share

Possible, but not likely. 99% of problems like this are caused by something else.

Have you tried putting the character in a new scene with just a flat plane?

Any scaling of things involved?

avatar image Kiwasi · Jul 01, 2014 at 08:22 AM 0
Share

Time.timeScale is not 0?

Show more comments

2 Replies

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

Answer by Magnomous · Jul 01, 2014 at 09:11 AM

Ok, I used a google and found very similar article:

http://answers.unity3d.com/questions/277402/controllersimplemove-having-issues-with-vector3for.html

The problem was, that my cube had a child object with collider touching the cube. When I checked child's object collider as Trigger, everything works correctly now. Thank you all for your responses.

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 unity_OGYwU_NIcUzFuA · May 27, 2020 at 10:01 AM

Sorry to dig up a very old post but this is the first one that comes when googling this issue. I just experienced troubles with SimpleMove myself and it took me all afternoon to figure out the problem, so I want to post the solution here for reference.

As it turned out, I was "breaking" my Character Controller by calling SimpleMove(somthing / 0f) at the very first frame. Even though I was calling it with reasonable values afterwards, it was completely unresponsive.

Since SimpleMove requires a speed, it's frequence to call it with a fraction of dist/time so be sure that you NEVER call it with a time of 0.

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

25 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Run speed in world-based character controller 0 Answers

Multiple Cars not working 1 Answer

C# CharacterController.SimpleMove Goes on Forever 1 Answer

Distribute terrain in zones 3 Answers

Time.DeltaTime doesn't seem to be correctly 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