- Home /
How to ignore specific collider, non-raycast?
Possible? I can't just disable the collider in my case, and cannot use a raycast approach.
Edit: More detail- I am trying to achieve a player, that is non playable, to be able to pass through a specific collider, while the player cannot. However now I am thinking of a different approach, and maybe just transform position of the NPC's mesh, and just repawning the collider and other stuff onto the otherside, once mesh gets there. So it would appear, that they had gone through, but really just repawned. It would be a little complicated because of moving the mesh, yet respawning also. So maybe make a ragdoll that animates and transforms position instead. IDK, I'm just throwing ideas out.
whats raycast have to do with it?
Are you trying to disable the object for the purposes of collision detection. Or perhaps for the purposes of collision detection against a specific second collider.
Often its best to say not what you need in coding terms but in non technical terms. Alot of times if you need something unique you really dont. You just havent thought of the ideal solution to your problem.
Perhaps you could say I need to be able to pass through walls temporarily or whatever your problem is in a non technical manner.
I think non-raycast was specified to say 'I cannot use layermask', and I can see where this situation of only allowing certain collision events could be applied hence the question.
Imagine the player character is a ghost, it can pass through walls but if it hits a lamp or flowerpot then use normal collision.
The question could use a much better description, but it is a valid and good question (I am also interested having written my own 'ghost' game).
As soon as I typed that I realized that what you need and are looking for is the Physics $$anonymous$$anager , in which case you can absolutely use layers : http://docs.unity3d.com/Documentation/Components/class-Physics$$anonymous$$anager.html
I have only used this matrix for raycasts, but imagine it does the same for all physics as it suggests. Do some tests and let us know =]
yea i mean i can guess what he might want but a better phrasing and description is needed really
There is sth: Physics.IgnoreCollision
I never used it, so I don't really know...
@bpears .........
Unity provides the option to avoid the collission of specific colliders. I will tell the process in your case: put NPC'c layer as "npc" and the block layer as "block" (or whatever except default). Now go to Edit> Project Settings > Physics ........ There you can see all the layer names in matrix form and all checked. Uncheck the one which intersect on "block" row & "npc" column or vice versa. Now these colliders will not detect each other...
Answer by Wolfrik_Creations · Dec 10, 2015 at 05:19 PM
Try putting something like this on your NPC
function OnCollisionEnter(col:Collision) {
if(col.gameObject.tag=="NoCollision") {
col.GetComponent.<Collider>().enabled=false;
}
}
function OnCollisionExit(col:Collision) {
if(col.gameObject.tag=="NoCollision") {
col.GetComponent.<Collider>().enabled=true;
}
}
but this might not work if your player walked at the same time as the NPC through the wall.
All else fails you could try not putting a collision on your NPC if that's an option.
Answer by dhore · Dec 11, 2015 at 01:02 PM
Use the Physics.IgnoreCollision function to tell the physics engine to completely ignore all collisions between 2 specific gameobjects.
Answer by Rad-Coders · Dec 10, 2015 at 10:48 PM
Add a new layer for all the colliders you don't want your NPC to collide with and a layer on your NPC. Then just edit the Layer Collision Matrix (Under Edit>ProjectSettings>Physics) so that they don't collide.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Collision detection in script not attached to either collider 1 Answer
How to treat Input.GetAxis as Input.GetButtonDown? 9 Answers
Convex collider sometimes works, sometimes doesn't. 2 Answers
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers