- Home /
Physics.IgnoreCollision on layers
Hello,
I am trying to implement a wall mounting system for my FPS. What I have is a box trigger near the edge of a rooftop (put in a layer called "Mount"), and if the player is inside the box trigger they can press space to mount over the edge. However, I am also using a downward raycast to check if the player is grounded. The box trigger is picked up by this raycast and tells the player he's grounded, when he's actually hanging off the edge of a roof in the air.
This is what I'm using:
var distToGround: float;
function IsGrounded(): boolean {
//Make this rigidbody ignore collisions against objects in the mount layer!
//Physics.IgnoreCollision(me, everything in mount layer);
return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.5);
}
And here is Mount.js (put on the player rigidbody):
var mountVector: Vector3;
var mount: boolean;
function ReadyToMount() {
mount = true;
Debug.Log("Ready to mount");
}
function NotReadyToMount() {
mount = false;
Debug.Log("Not ready to mount");
}
function Update() {
if (Input.GetKeyDown("space") && mount == true)
{
Debug.Log("Mounting");
rigidbody.velocity = mountVector;
mount = false;
}
}
And finally here is Mountable.js (put on the box trigger near the roof's edge):
function OnTriggerEnter (hit : Collider) {
if (hit.gameObject.tag == "PlayerFlying")
{
var target = GameObject.FindWithTag("PlayerFlying");
target.GetComponent(Mount).ReadyToMount();
}
}
function OnTriggerExit (hit : Collider) {
if (hit.gameObject.tag == "PlayerFlying")
{
var target = GameObject.FindWithTag("PlayerFlying");
target.GetComponent(Mount).NotReadyToMount();
}
}
Changing the layer collision setting wouldn't work because the collision still needs to register whether or not the player is in the mount box trigger. The whole thing would work fine if I could make Physics.IgnoreCollision(me, everything in mount layer) work. How can I accomplish that?
Thank you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103106im_/https://answers.unity.com/themes/thub/images/avi.jpg)