Question by
thinkablegamer · Jan 20, 2020 at 04:54 AM ·
scripting problemprogrammingsnapping
VR Object Snapping
Im working on a machine building system for the VR game im working on. when the part enters the trigger it snaps it to the attach point to show a part has been added to the build but the objects just flicker for a sec then nothing.`
public Transform AttachPoint;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter(Collider collisionInfo)
{
if (collisionInfo.tag == "Part")
{
transform.position = AttachPoint.transform.position;
gameObject.GetComponent<Transform>().SetParent(AttachPoint.transform);
}
}
}
Comment
Are you sure the if statement is running? Simply add a Debug.Log line to check.
Alternatively, change your code to this:
gameObject.GetComponent<Transform>().SetParent(AttachPoint.transform, false);
transform.localPosition = Vector3.zero;