- Home /
Trouble with Physics.IgnoreCollision
I'm having some trouble using Physics.IgnoreCollision, in my case the two colliders in the script below are definitely not ignoring each other when the scene is running. I've used this script before with no problems, so I'm not sure why it is not working.
Other info:
realterrain is a static mesh with a mesh collider
thiscollider is on a object with a rigidbody and mesh collider (convex)
Any ideas on why it is not working?
using UnityEngine;
using System.Collections;
public class ColumnCollision : MonoBehaviour {
//goes on upper most prefab object,
private GameObject realTerrain; //the actual floor for room 4 (that the player walks on)
private Collider thisCollider;
void Awake ()
{
thisCollider = gameObject.GetComponent <Collider>();
}
void Start ()
{
realTerrain = GameObject.Find ("WRFloor");
//Debug.Log (realTerrain.name);
Physics.IgnoreCollision (realTerrain.collider, thisCollider, true); //prevent terrain from kicking column up into air at start
}
}
Why do you need to use this? Your code suggests it's to prevent the column being kicked up into the air, perhaps check that the column isn't intersecting a tiny bit causing it to move apart? Also, the terrain should probably be using a terrain collider. I never need to use Physics.IgnoreCollision
with terrains.
Never actually heard of a "terrain collider" before, I'm guessing it works with Unity created terrains? (If so, I can't use it).
Anyway, the reason these columns are ignoring the terrain the player can move on is that the terrain is "soft" and the columns start sunken into the ground before dis-lodging (and are in fact using a flat collider under the terrain as their actual ground).
Your answer
Follow this Question
Related Questions
Mouse Movement with physics 1 Answer
Physics.IgnoreCollision not working 0 Answers
Surface with hole and Raycast - Which collider 1 Answer
Make Ray hit own collider 1 Answer
C# Check if Collider2D[] Doesn't contain Scripted GameObject 1 Answer