Hi, I have a question, is there a way to lock to a grid while raycasting.
Here is how I raycast:
var cam : Transform = Camera.main.transform;
var ray = new Ray(cam.position, cam.forward);
var hit : RaycastHit;
function Update(){
if(Physics.Raycast (ray, hit, Mathf.Infinity, myLayerMask)){
W_Wall_Model.transform.position = Vector3.Lerp(W_Wall.transform.position, hit.point, 50f);
}
}
I am aware that this only moves an existing object, This is what I use to snap to grid:
#pragma strict
function Start () {
}
function Update () {
var currentPos = transform.position;
transform.position = Vector3(Mathf.Round(currentPos.x),
Mathf.Round(currentPos.y),
Mathf.Round(currentPos.z));
}
But I have not found a way to raycast and snap the raycasted object to a grid. Does anybody have any ideas?