Search Unity

Question Setting Contact Offset Via Script Does Nothing

Discussion in 'Physics' started by Ultrasnowy543, Feb 1, 2024.

  1. Ultrasnowy543

    Ultrasnowy543

    Joined:
    Dec 26, 2022
    Posts:
    13
    Basically Setting Contact Offset In A Script Has Absolutely Zero Effect
    I Set It For A Collider And Nothing Happens
    However I Feel Like It's Something I'm Doing Wrong
    Any Advice Or Fixes?


    using UnityEngine;

    public class ColliderOffsetScale : MonoBehaviour
    {
    private Collider thisCollider;

    void Start()
    {
    thisCollider = GetComponent<Collider>();
    }

    void Update()
    {
    thisCollider.contactOffset = Physics.defaultContactOffset * transform.localScale.x;
    }
    }
     
  2. POOKSHANK

    POOKSHANK

    Joined:
    Feb 8, 2022
    Posts:
    289
    what is the use case here? i'm confused why you would do this as colliders scale with parent transforms. but anyway, it's definitely being set. rule of thumb is if you're not sure, debug it ~ its way faster to write one line of code than guess over and over.

    are you sure you want to use Collider and not CapsuleCollider or MeshCollider etc? collider is a base class and shouldn't really be used as a replacement for those if they're what's attached