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 MarkenhXu · Feb 03, 2021 at 07:55 PM · physics

Physics.SyncColliderTransform and Physics.SyncRigibodyTransform

So here is how to create this problem


  • put a character with an animator into the scene. (any animation, an idle standing aniamtion will do)

  • then open profiler and look under FixedUpdate.PhysicsFixedUpdate. You will see Physics.SyncColliderTransform and Physics.SyncRigibodyTransform both takes 0ms to process.

  • now add a collider and a rigibody to the character's bone. for example the head.

  • Then look at the profiler you will notice those 2 item now will take some processing time 0.05ms each or something like that.


    I think this is because the character is controlled by the animator which changes the transform position and rotation directly. so the physcis system needs to be updated to match the changes. But this process can get expensive if you have multipule units.


I want to have collider on the character's limbs because I want accuracte hit detection and bodypart specific damages. So each of my character have around 7 bone that have collider (head, chest, arms legs etc). if I have 50 characters on screen. just to sync those collider and rigibody costs my 2ms of processing time.


To get to 60 fps. I only have 16ms of processing time to spare. Those 2 things alone is using 2ms. So is there a way to optimize this while keeping colliders on the bones?

all ideas welcome

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
1

Answer by Bunny83 · Feb 03, 2021 at 08:40 PM

No, there's no way to optimise that when you use Unity's normal physics system. Of course with DOTS it's an entirely different story, but DOTS has a steep learning curve and requires a completely different setup. Also at the moment DOTS is still in preview stage, so going in production with that comes with the risk of intermediate changes and updates which could break existing code.


Of course if you just think about hit detection for your characters, you could of course do this without any collider or physics and just manually calculate intersections with different body parts. One of the easiest shapes you can detect intersections with is a sphere, capsule or cylinder as those boil down to a plain point - line or line - line distance calculation. Of course you could also think about a hybrid. So your character usually has at least one collider that covers the whole character. So you could use that to determine which character you needto check for hits. Instead of normal colliders you could attach your own script to each bone and store some parameters about that shape. So when your physics raycast hits the characters collider you just iterate through all of your "custom" colliders and mathematically check for a hit. This could be made quite advanced by writing some editor visualization tools for your custom colliders which would simplify the placement of those.


Though before you panic about the profiler values, I would highly recommend to just setup a test scene with about that many colliders / rigidbodies and see how it actually scales. in many cases the load does not scale linearly. Keep in mind that any object with a collider that moves on its own also needs a rigidbody attached. Though when controlled through the animator a kinematic rigidbody is enough. Never move a collider without a rigidbody. This would kill performance.

Comment
Add comment · Show 1 · 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 MarkenhXu · Feb 03, 2021 at 10:13 PM 0
Share

Thanks for the feedback. I did test with actual characters. Yes thank god the load does not scale linearly, if it did it would use up 10ms for 50 characters.

I was also looking at DOTS, but I feel it is not ready. Because it seems like you need to write your own math to perform alot of basic operation such as raycast, collision. Even unity's 2019 copenhagen example project have custom writen collision code so the entities can collide. At that point I am basically writing my own game engine.

I think your idea using 1 master collider to check for hits. then some custom code to make a estimated guess which bodypart it would have hitted seems reasonable. Wont be as accuracte since arms, legs and head may moving around. but I think perhaps chest, stomach and maybe upper leg could use this. Then I can at least reduce the number of actual collider on each character by half.

Well I guess at worst case, I will just have to squeeze some more performance out of my own code somewhere.

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

186 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 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 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 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 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 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 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

2D 360 degress platformer example needed 0 Answers

Raycasting to the bottom side of a plane? 2 Answers

How do I stop my player from very slowly sinking into the ground? 2 Answers

Run some code just after physics is calculated 1 Answer

bow and arrow game 6 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