I am working on a project that drops dynamic rigidbodies after clicking them. Using the code from this project: https://developer.playcanvas.com/en/tutorials/physics-raycasting-by-tag/
I am able to detect when something is being clicked by based on it’s tag on both entities with only a collision component, and entities that have both a collision component and an active rigidbody, but if the rigidbody component is disabled, the remaining collision component will not detect as a raycast result.
My thinking was to detect a click on the object before enabling the rigidbody and teleporting it to its correct position to drop through the environment.
I’m wondering if I should be approaching this a different way. Should I just leave the rigidbody enabled, but static then teleport it and make it dynamic (and immediately setting all of its physics properties)?
Internally, the rigidbody component will remember dynamic properties, like mass or angular factor. You can use that to your advantage by setting all these properties in advance to your static rigidbody (because its static, they will be ignored though).
Once you get a hit result, you can simply change the body type from static to dynamic. Internally, the engine will destroy the old body from the physics world, pick the properties required for the dynamic body from the component and introduce a new body to the world enabling its simulation.
Perfect! That’s good to know. I’ll refactor my code in that direction as I move along.
I feel like I saw something awhile ago about debugging collision shapes in the launch window, but I can’t seem to find it. I’ve checked and rechecked my entities, but for some reason the top left most chip does not register a raycast hit in that position:
In the Editor you can use the Physics Edit mode:
In the launcher there is no built-in method for debugging, but you can use third party tools/scripts:
DevTools by @yaustar:
Ammo Debug Drawer by me: