• 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 katarn321 · Dec 03, 2019 at 04:30 PM · physicstransform.positionoverlapsphere

Physics OverlapSphere not including object with rigid body that was moved using transform

I know that you usually shouldnt use a game objects transforms to move it around if you are using a rigid body that is not kinematic. But in this case I am trying to swap in a ragdoll version of my character when the animated version triggers a collider. The character triggers the collider fine and I can swap out the character for the ragdoll version just fine by altering their transform.position & rotation values. The issue im seeing is that Physics.OverlapSphere does not see the ragdoll game object unless I put some kind of delay in so that a frame or 2 passes before I check. If I move the ragdoll inside the sphere area im checking using the transform.position and then immediately call OverlapSphere it does not include the ragdoll in the collider array, Its like at the start of a frame there is some internal list of all game objects, their position and rotation and the Physics.OverlapSphere call is referencing that. So i doesnt matter if I move a game object to a point inside that sphere before hand, the call to OverlapSphere seems to go by the games objects position before I moved it in the script. Is this something anyone else has seen or expected behavior for the OverlapSphere method?

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 lgarczyn · Dec 04, 2019 at 12:59 AM 0
Share

Have you tried moving the rigidbody using rigidbody.position?

Also why do you need OverlapSphere to find the ragdoll, shouldn't you still have it?

Also why do you move the ragdoll away ins$$anonymous$$d of just disabling it?

Couldn't both the animator and the ragdoll be part of the same object and toggle from one to the other?

avatar image katarn321 lgarczyn · Dec 04, 2019 at 08:40 PM 0
Share

I have not tried moving with rigidbody.position, I can give that a try.

To expand a little on what im trying to do. Ive got an object pool of quite a few game objects which are enemies. Im also trying to avoid the SetActive(true) hit by keeping them active but with some of the components disabled. I keep this pool of enemies out of sight in the scene and swap them in when needed.

The basic enemy has 1 rigid body and animation and navmesh agent. So its not too big a hit to have 30 or 40 of these active and running around. When something happens to kill one of these enemies I am trying to swap it out and swap a ragdoll in and set all the ragdolls rigid bodies to is$$anonymous$$inematic=false.

I could have the main enemey fully setup with joints and rigid bodies on the main body parts but with 30 or 40 of them running around with that many rigid bodies it starts to kill performance on mobile (or an older tablet im testing with).

Anyway, I can work around the issue of the overlap sphere thing. I just found it odd that it could not detect something that was moved next to it in the previous line of script. I found a similar issue with the AddExplosionForce method. Even though i move the object right next to the explosion source in the pervious line of script it behaves as if the object is still far away with little or no force being added to the object.

avatar image Casiell katarn321 · Dec 04, 2019 at 10:08 PM 0
Share

it could not detect something that was moved next to it in the previous line of script

Nothing odd about it. You may have moved the object, but the actual physics update will occur only during the next FixedUpdate. Every physics component on that object will behave as though it's still on that previous spot until then.

Show more comments
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Dec 07, 2019 at 01:39 AM

Well, as others have already mentioned the positions of the colliders will only be determined by the next physics step. Funnily there was a kind of related question just 2 days ago. The issue is the same and the solution could also be the same. However it depends on your concrete needs.

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 katarn321 · Dec 07, 2019 at 03:35 AM 0
Share

Thanks for your response. I had come to the same conclusion but there really isnt any documentation about how the process works. I could root into the code but didnt want to. Ive coded for almost 30 years and I aint got time to go digging through someone elses code every time something doesnt work as expected. Its kind of funny, 30+ years ago I worked in a programming language called RPG. It was different in that there was a cycle, things repeated, there was this built in loop which is very much like the dealing with the game cycle. Anyway, thanks for your feedback, I learn something here every day.

$$anonymous$$at

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

Physics.OverlapSphere not detecting Instantiated Objects 1 Answer

Instantiate problem with multiple objects from an array 0 Answers

Whats Wrong? 1 Answer

hit.rigidbody.useGravity problem? 1 Answer

OverlapSphere, check how many object with specific tag did it collide with.. 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges