- Home /
Get vertices inside a box collider
Hi all
I would like to change the y-value of vertices in a plane when an invisible cube goes trough them. I can't figure out how to find the specific vertices that are inside that cube.
Any suggestions?
Cheers
Answer by Berenger · Jan 07, 2015 at 01:30 PM
Check this out : http://docs.unity3d.com/ScriptReference/Bounds.Contains.html
That helps when the box is axis-aligned. OP did not specify this. If the box is rotated, then?
You simply use the colliders center and size value to create a "local bounds" struct. Now you just need to transform the vertices into the local space of the collider. $$anonymous$$eep in $$anonymous$$d that vertices of a mesh are in local space of the mesh object.
So you need to do a "TransformPoint" using the Transform of the mesh to actually get the worldspace position of a vertex and then "InverseTransformPoint" using the Transform of your collider. So the resulting position is in local space of the collider. There you can do an axis aligned bounds check.