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 dream1446 · Jun 15, 2012 at 12:20 PM · character controllerrtsfixedupdate

Best way to simulate Character Controller under Fixed Update?

Hi, my question is what is the best way to simulate a Character Controller, which is based on Update and Time.deltaTime, under FixedUpdate?

I tend to achieve the same effects of Character Controller that is able to move base on speed cmd, has simple collision exclusion with others but with no physics simulation of the collision that mess up the rotation and position after collision, able to stand and move along curve 3d ground (stand normal to its current ground position).

  • I have tried rigidbody with colliders, use set velocity to move, but but a single collision with other object would mess up the movement. If I lock the X,Y,Z rotation and position, then I am not able to make it move along the curve of the ground.

  • Another approach I am now considering is applying a extremely long collide box along y axis for each unit, which guarantee an intersection with the ground. Then, at each FixedUpdate, check the intersection position and normal with the ground, then adjust the stand stance of the unit and make the movement based on the normal. But this sounds quite low efficiency, as it needs to check for the collision on each FixedUpdate(physical update) loop.

Is there any better way to achieve the Character Controller based on FixedUpdate? Or is there any source code or underneath mechanism of the Character Controller I can reference to? Many thanks in advance for any help

I am asking such a question because I am aiming to develop a 3D RTS game that supports multiplayers, and tend to use lock-step technique to achieve that (1500 Archer Technique). Thus I can not rely on Character Controller for units as it is based on Updates, which means its movement may varies based on frame rates.

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 Owen-Reynolds · Jun 15, 2012 at 02:53 PM

You should be able to reuse any charController script almost exactly as-is -- change Update to FixedUpdate and fix the minor problems:

o Replace Time.deltaTime with Time.fixedDeltaTime.

o Anything that samples 1-time input will need to be moved to an Update (FixedUpdate can miss seeing them.) For example: global bool jumpNow;, set true in Update if jump key pressed. Checked at usual place in FixedUpdate and reset to false afterwards.

o I believe Vert/Horizontal Axis is fine to check in FixedUpdate. Unity is maintaining the values for you. You may need to check the scroll-wheel in Update (it may count each scroll-tick as a discrete event.)

Comment
Add comment · Show 3 · 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 dream1446 · Jun 15, 2012 at 06:10 PM 0
Share

Thanks for the reply :)

  • The CharacterController is a binary component rather than a modifiable script if I get it right, how can I modify it?

  • Ins$$anonymous$$d of fixedDeltaTime, I tend to use some constants, so the movement is actually based on the number of loops rather than the actual time passed. This is required by the lock-step technique.

  • Input will be handled in Updates, yes, thanks for the re$$anonymous$$der :)

  • The problem with rigidbody and Vert/Horizontal Axis is that, objects keep bouncing with each other when they collide, which I don't want. But if I freeze the rotation and position of the rigidbody, then I get no access to 'set velocities' and make the rigidbody moves along the ground. Is there a way to cancel the bouncing, and make rigidbody movement applicable at the same time?

avatar image Owen-Reynolds · Jun 15, 2012 at 07:14 PM 0
Share

The interesting part of a CharContr is the built-in $$anonymous$$ove function, which simulates a "physics move" (and isn't linked to Update.) There are a number of scripts (some in Unity Standard Assets) which "run" a character controller. They are the things that generally run in Update, but could run in Fixed.

Yes, rigidbodies bounce around. The CharCont+script approach is specifically meant to not do that.

avatar image dream1446 · Jun 16, 2012 at 11:10 PM 0
Share

Ok, Will go and have a look on those. Thanks for the answer again :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to call a method once inside fixed update 1 Answer

Keeping A Character On The Terrain (Allow no Y movement) 2 Answers

need help in an RTS game...needed fast....very badly! 0 Answers

How to reset attack animations using time.deltatime 2 Answers

Avoid iterating through all gameobjects to select units using marquee selection box (selection box is already created, just have to be efficient) 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