Before updating to Windows 10 you may need to return your Pro license. More information here

Snap to point

I've been trying to make a snapping system, so a number of empty gameObjects are defined 'ClippingPoints' and are tagged thus. I've been trying to make snapping work with this script, however, it's not working well - objects are snapping to really weird places. Here is the part where I define and place objects.

 function Place (){
     clippingPoints = GameObject.FindGameObjectsWithTag("ClippingPoint");
     var position = transform.position;
      var distance = Mathf.Infinity;  
      var closest : GameObject; 
     for (var go : GameObject in clippingPoints) { 
     var diff = (go.transform.position - position);
     var curDistance = diff.sqrMagnitude; 
 if (curDistance < distance) { 
 closest = go; 
 distance = curDistance; 
 if(distance < 1 ){
 if(snapping == true){
 newPart.position = closest.transform.position;
 print (closest.transform.position);
 currentPart = false;
more ▼

asked Jan 06, 2012 at 11:53 AM

avatar image

1.4k 206 172 185

I think the code could be a bit more complete but I suspect the problem is related to you getting the information from transform.position, altering newPart.transform and then setting newPart.position (but if newPart is a transform, why did you call newPart.transform?)

Jan 06, 2012 at 01:09 PM Toeofdoom
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jan 06, 2012 at 11:53 AM

Seen: 1767 times

Last Updated: Jan 07, 2012 at 10:37 AM