Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Does not collide

Discussion in 'Physics' started by QuackedUp, May 3, 2021.

  1. QuackedUp

    QuackedUp

    Joined:
    May 3, 2021
    Posts:
    10
    https://imgflip.com/gif/583dh0

    My script :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PickUp : MonoBehaviour
    6. {
    7.     Rigidbody m_Rigidbody;
    8.  
    9.     void Start()
    10.     {
    11.         m_Rigidbody = GetComponent<Rigidbody>();
    12.  
    13.     }
    14.  
    15.     public Transform theDest;
    16.  
    17.     void OnMouseDown()
    18.     {
    19.         GetComponent<Rigidbody>().useGravity = false;
    20.         GetComponent<Rigidbody>().isKinematic = true;
    21.         this.transform.position = theDest.position;
    22.         this.transform.parent = GameObject.Find("Grab Slot").transform;
    23.         //GetComponent<Rigidbody>().freezeRotation = true;
    24.         m_Rigidbody.constraints = RigidbodyConstraints.FreezePosition;
    25.     }
    26.     void OnMouseUp()
    27.     {
    28.        this.transform.parent = null;
    29.        GetComponent<Rigidbody>().useGravity = true;
    30.        GetComponent<Rigidbody>().freezeRotation = false;
    31.        //GetComponent<Rigidbody>().isKinematic = false;
    32.        m_Rigidbody.constraints = RigidbodyConstraints.None;
    33.     }
    34.  
    35. }
    36.  
    37.  
    Problem is i don't want it to go through the floor/wall but I don't know how should iresolve this.

    How should i resolve this?