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

Muzz5 gravatar image

1.3k 205 169 181

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: 1600 times

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