Basically I’m trying to make a particular object scale based on its distance from the camera, which means I have to scale it in Update(). Here is a pic to show what I’m doing: http://i.imgur.com/83d1aeP.png
The problem is that when I scale this object, it also scales the colliders which kills performance. The profiler tells me “Mesh.Bake Scaled Mesh PhysX Collision Data” is taking up 76.8% of processing time (~2000 fps → ~200 fps with v-sync off).
Is there any way to scale the MeshFilters only and not the colliders? Or is there a way I can scale the vertices on the MeshFilters? The object is composed of multiple filters/colliders so I can’t really just scale the mesh.vertices for each MeshFilter (they will scale relative to their own centers/pivot points, not relative to that grey center dot in the pic above).
I still need the MeshCollider to be available and I would just update it before doing any ray casting so I can’t just delete it. If anyone can help me out then I’d really appreciate it.
Here’s my current code for scaling:
Vector3 distance = transform.position - Camera.main.transform.position;
transform.localScale = Vector3.one * 0.03f * Vector3.Dot(distance, Camera.main.transform.forward);
Wouldn't you be better off using another camera to render that object at the same location as the world x/y coordinates converted to the camera's screen coordinates? That way it wouldn't have to change size...
– whydoidoitI need the collider because I'm doing ray casts on it. If you look at the picture ([http://i.imgur.com/83d1aeP.png][1]), you will see some arrows which are all selectable if you click them. Whydoidoit, that solution seems great but how exactly would I go about doing it? [1]: http://i.imgur.com/83d1aeP.png
– PanzerTFRemoving the colliders (scaling only the MeshFilters) does fix the fps issue, I've tried this already. Also I am using a sphere collider for the sphere but I'm using mesh colliders for the arrows/squares. If possible I'd like to know how to do what Whydoidoit is talking about since it sounds like a clean, efficient solution.
– PanzerTFSo create another game object with a camera on it - like @Fattie says, stick it out of the way somewhere. * Make that camera render only a layer for the UI. * Make your UI object and scale it so it looks right in that camera, * Make the camera clear depth only * Get the WorldToViewportPoint of the thing selected using the main camera * Position your UI at the same viewport point in the other camera (Using ViewPortToWorldPoint with the current z position of your UI).
– whydoidoitAlright, I'll try that out. I've never really messed with cameras like this before. Just so you guys are clear, I'm making something very similar to how the built in move tool works in unity. I appreciate the help and I'll let you guys know how it goes.
– PanzerTF