- Home /
Is it possible to do inverse transformations, instead of moving complex groups of objects?
CONTEXT
So I have a fairly simple room that is marked as static, and a complex geometry with a few hundred box colliders on it in the middle of the room. I know that's a lot of colliders. My game is in VR, which has trouble with mesh colliders for some reason. I think it has to be convex or something and then you're limited to 255 verts, but my object is concave and has tens of thousands of vertices, so getting a simple mesh collider to work would be a headache. My object and its colliders are also generated at runtime (shoutouts mynameisjacob for this awesome compound collider generator), so simplifying my mesh within Unity in order to make a simplified mesh collider for it also seems like it would be a headache.
So I have a simple static room with a complex object. This works well when the object isn't moving, but I need to grab the object and move it. This causes massive a performance drop whenever the object is moving since every frame (or more) the CPU needs to update the transform of each collider. I'm looking into simplifying this and running it in parallel using the new ECS and Job System, but I still want to look into my question for possible further performance gains.
MY QUESTION
If I have a large group of transforms that I need to move at once (My complex shape with a 600-box compound collider), and that is the only thing in my environment that is going to move at any time, is it possible/convenient to move my environment relative to the object, instead of moving my object relative to (0, 0, 0) in world space? Instead of moving my 600 colliders, can I move my static environment and lighting around the object, so that the effect is exactly the same, but fewer transforms need to be updated?
Simple example: I grab my object and move it from (0, 0, 0) to (1, 0, 0) and the object's rotation moves from (0, 0, 0) to (90, 0, 0). Is there a simple code implementation to instead move all of my static marked objects from (0, 0, 0) to (-1, 0, 0) with rotation (-90, 0, 0), so that you as the user cannot tell the difference, but fewer objects have had their transforms altered? Or would it require simply saving all of my static objects in an array and running through their transforms with a for loop, doing the math each frame to find the inverse transform? Cause that seems too inefficient.
You could have a duplicate of your object with fewer colliders and switch between them using gameObject.active, unless you need it to collide accurately with the environment.
I wouldn't recommend moving the environment itself, which you could do by parenting the whole lot to an object at the players position and moving it negative to the player. You'd have to keep reparenting it to bring it to the players new position.
Your answer

Follow this Question
Related Questions
Trying to make an object "Flee" from the player but it won't work? 3 Answers
How to make a world-space UI panel that can find an open position in the world? 0 Answers
Line render from an object to a click 0 Answers
My gameobject only moves to the right once and then stops, why? 3 Answers
transform.Translate not working after exporting to Android 2 Answers