Drill a Hole on a Plane

So, I need some strategy advice. I’m working on a project where I need to drill a hole in a sheet of wood. The user needs to decide where to drill the hole.

Now, I don’t think I need to actually make a hole (I’m going to fake it with an object or texture that looks like a hole), but I’m trying to figure best how to make this all work.

I’ve been thinking of doing this:

  1. With a fixed camera show the entire sheet.
  2. Allow the player to use their mouse to mark the hole on the sheet of plywood. Presumably this would be done with Raycasting?
  3. Return this location, then move the camera to center on it, and play the animation of the drilling drill.
  4. Place the object of the ‘hole’ over that same spot.

So, my questions are:

  1. Does this seem like a reasonable strategy?
  2. Does anyone have some sample code of using raycast to return a specific point on a surface?

OK…so documenting the process, I’ve got so far:

function Update(){
	var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	var hit : RaycastHit;
	if (Physics.Raycast (ray, hit, 100)) {
		Debug.DrawLine (ray.origin, hit.point);
			if (Input.GetMouseButtonDown(0)){
			Debug.Log ("Location" + hit.point);
		}
	}
}

Yes, what you describe sounds reasonable.

since Jesse answered part 1, I’ll toss up part 2 I guess :slight_smile: Keep in mind I’m at work atm and cannot actually test this code

in JS:

var myRay = Camera.main.ScreenPointToRay (Input.mousePosition); //from camera point in the direction of the mouse

if (Physics.Raycast (myRay, 100)) {//returns true if the ray hits an object within 100m of the camera
  //insert your code here
}

If you’d like it converted to c#, just ask. For more examples of the above:
Check Here