I'm trying to make a "Worms" type game where an object falls from above and impacts a plane with a texture and causes a portion of the terrain to erase when it contacts a non-transparent part of the texture.
Code I'm currently trying to use can be found here: http://www.pasteit4me.com/2277018
Imagine the surrounding black box is the plane where the image texture ends and the rest is just transparent texture. The red box is the cube mesh that intersects the plane from above. Falling onto it along the same Z axis.
So far I'm able to use Raycasting to get the texture coordinates using mouse input through a script attached to the plane's Update() method:
RaycastHit hit;
if (Physics.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out hit))
return hit.textureCoord;
This works fine as a texture eraser using the mouse, but when I try to use a colliding object instead (simple cube), I can't seem to get the texture coordinates (come up zero), even though a collision is being registered. The plane is set to be a trigger, so I'm trying to use OnTriggerStay() to do a raycast from the colliding object's position.
I'm thinking I'm somehow not properly translating the position of the cube in space to planes texture. Though I thought that's what the RayHitcast.textureCoord is supposed to represent.
Please let me know if any clarifications are in order. Thanks!