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 miszelfox · Oct 26, 2014 at 10:21 PM · charactercontrollerfunctionmove

How to move character by command?

I am using Character Controller and i want to know how to move my character using command, for example i want my character to step back (move few units backward), but it should move, not be teleported by instant. I've tried to do this using "for" loop and "waitforseconds" but it's not enough. "waitforseconds" has big limits, so even if i put "0.0000000000001" seconds it doesn't move that fast.

Here is my function:

 function jump()
 {
 var controller : CharacterController = GetComponent(CharacterController);
 var i :byte;
 for(i=1;i<=60;i++)
     {
     moveDirection = Vector3(0, 0, -1);
     moveDirection = transform.TransformDirection(moveDirection);
     moveDirection *= speed;
     controller.Move(moveDirection * Time.deltaTime);
     yield WaitForSeconds(0.000001);
     }
 }
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

Answer by JanusMirith · Oct 26, 2014 at 10:37 PM

If you just want to wait for a frame then you need to use:

 yield;

But you still have a issue with your logic, here you do something for a set number of frames, this would make the action behave differently at different frame rates.

You would need to use a counter:

 float time;
 while(time<1f){
    time += Time.DeltaTime;

    //Do your code here
    yield; // wait for a frame

 }

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 miszelfox · Oct 26, 2014 at 10:49 PM 0
Share

Thanks, yeah i know it would, but it's not bad? I mean Update (function where normal moving is made) is updated once per frame too, so lower framerate will make all of them (normal moving and my jump function) just slower so it's okay.

avatar image JanusMirith · Oct 26, 2014 at 11:29 PM 0
Share

You are going to regret that sooner or latter. It is best to design from the start to be frame rate independent.

Regardless is the yield command what you were looking for?

avatar image miszelfox · Oct 27, 2014 at 08:58 AM 0
Share

Why? Function "Update" is updated once per frame, so you say that we shouldn't use this function?

avatar image screenname_taken · Oct 27, 2014 at 09:58 AM 0
Share

It is updated once per frame, but framerate is hardly consistent. Things will zip along in faster devices and things will crawl along in slower ones. Your movement won't be consistent. So if you have something that is dependent on correct movement, it won't work. That is why that deltatime is used. A projectile for example needs to be frame rate independent.

avatar image miszelfox · Oct 27, 2014 at 01:42 PM 0
Share

I don't understand what do you mean, so how my function should look like?

I have this:

 function jump()
 {
 var controller : CharacterController = GetComponent(CharacterController);
 var i :byte;
 for(i=1;i<=10;i++)
     {
     moveDirection = Vector3(0, 0, -6);
     moveDirection = transform.TransformDirection(moveDirection);
     moveDirection *= 3;
     controller.$$anonymous$$ove(moveDirection * Time.deltaTime);
     yield;
     }
 }

So fix that if you can, to move my character for 60 units backward.

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

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

Related Questions

CharacterController.SimpleMove() doesn't exist? 0 Answers

Very Simple Left and Right Movement Script [OR] disable dravity on CharacterController? 2 Answers

Move() function doesn't work on character controller! 0 Answers

Help with CharacterController.Move 0 Answers

Character Flying around uncontrollably 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