- Home /
Question by
Jonathan459 · Jun 23, 2015 at 02:41 PM ·
raycastnormalsmesh colliderdecals
Raycast on Mesh collider
Hey all.
I have a projector who projects a decal over a static mesh with mesh collider.
My goal is to slide the decal over the mesh while keeping the decal aligned to the mesh normals (so the decal wont stretch on corners and such)
I use a code snippet which uses raycasting to the mesh collider and rotate the projector to face the normals of the mesh. this is not working, the projector sometimes aligned and sometimes detach from the mesh into space.
did anyone had this issue before? i looked in the forums and find similar things but not something that helped.
the code i currently have is this:
void Update()
{
Vector3 castPos = new Vector3(transform.position.x + 1f,transform.position.y,transform.position.z);
RaycastHit hit;
if(Physics.Raycast(transform.position,transform.forward,out hit))
{
transform.rotation = Quaternion.FromToRotation(transform.position,hit.normal);
}
Debug.DrawRay(transform.position,transform.forward,Color.magenta);
//set the position close to the target object (so it wont drift while sliding)
transform.position = (transform.position - _target.transform.position).normalized * distance + _target.transform.position;
}
Comment
Your answer
Follow this Question
Related Questions
Draw Normal from Barycentric Coordinate (?) 1 Answer
How to do legdegrabbing 1 Answer
How do I return local normals? 1 Answer