Home > database >  OnTriggerEnter increase the colliding object size?
OnTriggerEnter increase the colliding object size?

Time:11-13

I have a simple cube, which's collider I am using as a invisible wall ( border ), to which I have attached the script below, so when an other object ( let say Object A ) hit it - it should be sent to a specific point ( Globals.ornamentsCreationPoint ). Yet, instead - the size of the "Object A" increase ginormous and it is not sent to the specific point.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OuterBordersCollider : MonoBehaviour
{
    private void OnTriggerEnter( Collider other )
    {

        other.gameObject.transform.SetParent( Globals.ornamentsCreationPoint.transform, false );
        other.gameObject.transform.position = Globals.ornamentsCreationPoint.transform.position;
        other.gameObject.transform.gameObject.AddComponent<Rigidbody>(); //?

    }
}
  • Why the object size increase ?
  • How can I send the colliding object "Object A" to Globals.ornamentsCreationPoint.transform.position on collision ?

CodePudding user response:

I can't say for sure based on only that bit of code, but since you are changing the parent with .setParent(), that might have something to do with it.

Since an object inherits the size of its parent, perhaps the moment you parent it, the (perhaps larger) scale of the parent applies and thus it appears as if the object itself had its scale increased.

  • Related