I have a weird issue I’m trying to resolve. Obviously there is something I’m doing wrong.
I’m trying to setup a basic object movement script in game so I have a script attached to a gameobject that handles movement with the mouse. It does a raycast call to determine where the object should be placed while moving as well as how it show be oriented as I want it oriented to the surface we are colliding with as we drag the object around.
Now also I want to sticky objects together so that if I move object A on top of object B object A is now a child of B. I have it basically working with the below script, but for some reason while I move my object around it is scaling the object in weird ways. It seems to be caused when I attached the object to what it is colliding with, but I’m not sure why. I assume it has something to do with local vs world transform, but there should be a way to do this. Thanks for any advise on this matter.
Code in Update function for gameObject…
if(isSticky){
var mousePos = Input.mousePosition;
var hitray : Ray = camera.main.ScreenPointToRay(mousePos);
var hit2 : RaycastHit;
if(Physics.Raycast(hitray, hit2, 1000)){
transform.position = hit2.point;
var rot = Quaternion.FromToRotation(transform.up, hit2.normal);
transform.rotation *= rot;
transform.parent = hit2.transform;
}//if
if(Input.GetMouseButton(0)){
setSticky(false);
}//if
}//if