Quantcast
Channel: Questions in topic: "ignorecollision"
Viewing all 148 articles
Browse latest View live

ignore collision question

$
0
0
I am trying to get a projectile with a rigidbody to collide with a box with a rigidbody. after the projectile collides with the box, I need the projectile to instantiate itself in the direction of the normal of the box. I need the new instantiated projectile to ignore all collisions with the box it collided with, but be able to collide with the other boxes in the same layer! unfortunately once the projectile instantiates it collides with the box again. I wanted to try using physics.IgnoreCollision(collider, other.contacts[0].collider); this way the projectile will ignore the first object it comes in contact with. it says that IgnoreCollision can't reference the same two shapes however? can someone help lol

Ignore individual collisions between two objects

$
0
0
I want to ignore collisions between an object and a special class of objects only when the collision contact point meets a few criteria. In other words: function OnCollisionEnter(other : Collision) { if (isSpecial(other.gameObject) && meetsCriteria(other.contacts[0].point)) { // Ignore this individual collision } } However, I don't want to use `Physics.IgnoreCollision(other.collider, collider)` because I want future collisions to still happen. Any thoughts? I will probably have to default to some kind of hackery where I remember what colliders I've ignored and then reenable collisions later, but I'd like to have a cleaner and less hacky solution. Thanks!

How to stop an Interactive Cloth colliding with box collider

$
0
0
I've implemented a netting for a goal which I have eventually got working in a way which I am happy with. However to get the correct reaction I have set the Thickness to 0.55. The problem that this brings is that the net (cloth) collides with the ground, a box collider, and because of the thickness it lies above the ground. If I could get the net (cloth) to ignore the collision with the ground it would work. But I have tried using `Physics.IgnoreCollision` but cannot find the collider for the Interactive Cloth. Is there a way to get `Physics.IgnoreCollision` to work? Or any other way I can stop the Interactive Cloth colliding with the box collider?

ignoreCollision information disappearing for prefab'd objects

$
0
0
Hi all, I've been working on a game with several characters. In one script, attached to a gameobject in all our scenes, we set the colliders on those characters to ignore collisions with one another. This has always worked for us. Recently, we decided to prefab our characters to make it possible to move them between scenes. However, we're noticing that if we create those characters in a scene from our prefabs, their collisions aren't being ignored if we close Unity. Right now, we have this scenario: Scene A has our original characters, not from prefab; We create a prefab for each character from the characters in scene A; We add instances of those prefabs to scene B (by dragging-and-dropping) When we run the game with our newly-added prefabs, everything works well. However, once we close and reopen that scene, they'll start colliding with each other again. I know for sure that our script ignoring collisions is present in both scenes; again, the ignore-collision logic works the first time we add the characters, but it stops working once we reopen the scene. I've been through the unity documentation on prefabs and Physics.IgnoreCollision, and haven't seen anything that helps me make sense of this. I know that IgnoreCollision doesn't persist, but I don't know prefabs well enough to say if that's what's causing the issue in this case. Any advice would be greatly appreciated. Thanks!

Physics.IgnoreCollision on layers

$
0
0
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.

IgnoreCollision after a collision takes place.

$
0
0
So with no luck I been trying to cause a projectile that hits enemies only once before ignoring it. Of course since this projectile sticks around for a moment, it can't just ignore the collisions of all enemy characters, or disable it's own collision due to this. I just want collisions to disable specifically for that single enemy, which must happen after the projectile collides with it. I really thought this would work, however while everything in the code works, it never does the IgnoreCollisions for the next time the enemy collides with this projectile. function OnCollisionEnter(enemy : Collision) { Physics.IgnoreCollision(enemy.collider, collider); //Do stuff to the enemy here. } Any help would be appreciated, I can't figure out why this wouldn't work if in Start and Update functions IgnoreCollision generally works fine.

Code works fine until I turn the object it interacts with into a prefab.

$
0
0
Hi, I'm new to Unity and working on a 2.5D platformer as my first project. With some Google-fu and the help of already answered topics on this very forum, I've managed to figure out how to create platforms that the player can jump up onto from beneath and can also fall down through. I have a box collider trigger volume childed to my platforms that turns off the collision between the player and the platform for jumping up beneath them, and the collision box doesn't hit the top of the platform so it only works when jumping from beneath - exactly as I want it to. This is the code I have attached to the trigger volume: using UnityEngine; using System.Collections; public class PlatformJumpThrough : MonoBehaviour { private Collider collis1; private Collider collis2; void Start () { } void OnTriggerEnter(Collider platformCollider) { platformCollider.gameObject.layer=4; var platform = transform.parent; collis1 = platformCollider.collider; collis2 = platform.collider; Physics.IgnoreCollision(collis1, collis2); } void OnTriggerExit(Collider platformCollider) { platformCollider.gameObject.layer=0; Physics.IgnoreCollision(collis1, collis2, false); } void Update () { } } For allowing the player to drop down through the platforms, I have a very similar code setup, except without the trigger volume. This code is attached to the player: using UnityEngine; using System.Collections; public class JumpDown : MonoBehaviour { private Collider collis1; private Collider collis2; public GameObject platform; void Start () { collis1 = gameObject.collider; collis2 = platform.collider; } void Update () { if(Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)){ gameObject.layer=4; Physics.IgnoreCollision(collis1, collis2); } else if(Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.DownArrow)){ gameObject.layer=0; Physics.IgnoreCollision(collis1, collis2, false); } } } The problems occur when I turn the platform & trigger volume into a prefab. I set the public GameObject platform in the JumpDown code to the prefab instead of just the one object, and the first code seems to function fine and works as expected, but when I try to fall through the platform I am greeted with this a crash and this error:> Ignore collision failed. Both> colliders need to be activated when> calling this IgnoreCollision> UnityEngine.Physics:IgnoreCollision(Collider,> Collider, Boolean) JumpDown:Update()> (at Assets/JumpDown.cs:25) The colliders seem to be active by default and the player is able to stand on the platforms just fine. It only seems to throw the error when I try to fall through. (On KeyDown S or KeyDown DownArrow) Any idea what could cause this issue? Thanks!

How to ignore a raycast collision with a particular object?

$
0
0
I have a raycast and there can be multiple objects in front of the object that casts the ray. I want to ignore some of the objects, say object A (tag). In the below situation, I want the raycast to hit to the object B (tag): Player raycast ---- A ---- B ---> I have seen some answers including "layers". I have no idea if they are necessary in this siutation, and I don't know how to use them or what they are, either. How am I supposed to do this?

Ignore collision between character controller and a rigid body object

$
0
0
How would i ignore collision between the two colliders... thanks:)

Ignoring collision on parent but not children

$
0
0
I've got a number of projectile rigidbodies, and a group of character controllers. These character controller colliders are used ONLY for traversing the terrain, and within the character controllers are a hierarchy of child objects that contain (among other things) a series of colliders to be used for collision and raycasting purposes. I've used Physics.IgnoreLayerCollision to make the projectile layer ignore collisions with the character controllers. The character controllers themselves are on the ignored layer, while its child hierarchy is on the default layer. I expected this to allow the projectiles to pass through the character controller collider and not the children, but they pass through the entire hierarchy. Is there a workaround for this?

Physics2D.IgnoreCollision Not Working

$
0
0
Hey guys, the following script isn't working. When the collider enters the enemy, it doesnt ignore the collision, but collides and bounces off. ALL COLLISIONS WERE IGNORED!!!! and Enemy was hit are logged and shown when the collision happens, but they bounce off anyway. Can someone please help? Thanks in advance! This is a 2D game. void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Player")) { Debug.Log("player is dead"); } else if (collision.gameObject.CompareTag("Prison")) { } else if (collision.gameObject.CompareTag("Enemy")) { Physics2D.IgnoreCollision(collision.collider, gameObject.collider2D); if (Physics2D.GetIgnoreCollision(collision.collider, gameObject.collider2D)) { Debug.Log("ALL COLLISIONS WERE IGNORED!!!!"); } Debug.Log("Enemy was hit"); } else { Destroy(this.gameObject); } }

IgnoreLayerCollisions 2D works but it doesn't work?

$
0
0
void Update() { if(Input.GetKeyDown(KeyCode.Space)) { Physics2D.IgnoreLayerCollision(9, 10, true); } else if(rigBody.velocity.y < 0.05f) { Physics2D.IgnoreLayerCollision(9, 10, false); } } basically what the problem is the ignorelayercollision doesn't work in some places of the collider for example if i have a large platform i want to jump onto its a straight edge collider and in certain places the collider isn't jumping through it acts as if there is no ignorecollider but if i move over just a few centimeters then it works.

Ignore collision failed. Both colliders need to be active

$
0
0
I instantiate a ball in a gameObject script of a character so that the character has a ball to play with. I try to ignore collisions between the ball and the gameObject and when I do I get this error. Ignore collision failed. Both colliders need to be activated when calling this IgnoreCollision ball=Instantiate(Resources.Load("Sphere")); ball.name=gameObject.name+"ball"; ball.rigidbody.isKinematic=true; ball.rigidbody.useGravity=false; ball.GetComponent(SphereCollider).isTrigger=false; Physics.IgnoreCollision(ball.GetComponent(SphereCollider),gameObject.GetComponent(SphereCollider)); Is this happening because something is not fully loaded? How do I fix it?

Reset Trigger State without completely ignore collision

$
0
0
Is ther a possibility to reset the trigger state, I mean to force the triggerexit but not completely ignore the collision forever?

Physics.IgnoreCollision not working

$
0
0
So I have the following script on a few empties with box colliders set over water so that if you are flying, you cannot fly over the water, but you can walk into the water. It works great for the character, however other objects will still collide with it. I've put Debug.Log on the script and I'm getting them to register and no errors are showing. Please let me know if you see a reason for why other object would still collide with the object this script is on or another way to do this if not. Thanks! public GameObject text; public GameObject player; Collider detector; void Start () { detector=GetComponent(); } void OnCollisionEnter (Collision col) { if (col.gameObject==player) { if (player.GetComponent().hovering) { text.SetActive (true); }else { Physics.IgnoreCollision (player.GetComponent(),GetComponent()); } }else{ if (col.gameObject.GetComponent() !=null) { Physics.IgnoreCollision (col.gameObject.GetComponent(),GetComponent()); }else if (col.gameObject.GetComponentInChildren() !=null) { Physics.IgnoreCollision (col.gameObject.GetComponentInChildren(),GetComponent()); } } } void OnCollisionExit (Collision col) { if (col.gameObject==player) { text.SetActive (false); } }

How to ignore multiple colliders in IgnoreCollision

$
0
0
I have one game object with one collider, then another with 3 colliders(1 box and 2 circle), I use ignore collisions on both but only the box collider in the 3 collider game object is ignored, when I want all colliders in the gameobject to be ignored. Here's the code I use. if (platBounds.Intersects(gcGO.GetComponent().bounds)) { Debug.Log(1); Physics2D.IgnoreCollision(mainGO.GetComponent(), col.gameObject.GetComponent(), false); } else { Debug.Log(2); Physics2D.IgnoreCollision(mainGO.GetComponent(), col.gameObject.GetComponent(), true); } any idea what I'm doing wrong.

How would I create a raycast that ignores Character Controller

$
0
0
I am currently making an foot IK system right now for my game. But despite all of my dificulties the only problem I have is that whenever I enable my character controller the collider blocks off my raycast for foot IK, so I get this floating effect. Is there any way I can make my raycast ignore my character controller. I know how to utillize layers, but the problem is that the component, character controller collider, cannot have a layer? or can it? How would I make my raycast ignore the character controller?

Setting IgnoreCollision on Network spawned objects. (Unet)

$
0
0
I'm using the new Unet and got some problems with the NetworkServer.spawn method and collisions. [Command] public void CmdSpawnProjectile(Vector2 position, Vector2 direction) { GameObject proj = (GameObject) Instantiate(projectile, position, Quaternion.identity); Physics2D.IgnoreCollision(proj.GetComponent(), GetComponent()); proj.GetComponent().velocity = direction * force; Destroy(proj, 2f); NetworkServer.Spawn(proj); } The ignore collision works fine on the host as expected. But that won't apply to the other clients which ofc is logical. The question is how to apply the Physics2D.IgnoreCollision on the clients as well. Everything works perfectly except the projectiles spawned on the clients collides with the player who spawns them. (Simply spawning the projectiles outside the collision of the spawner is not a option.)

IgnoreCollision affecting children & unrelated objects when it should'nt ?

$
0
0
I've encountered what I think is a bug - sent a bug report about 1 week ago but I thought Id mention it here. **Scene :** - One moving cube "CubeA", one large flat cube for the ground "Base", one trigger volume "Trigger" child of "Base", one non-moving cube "CubeB" already inside "Trigger". - "Trigger" has a script monitoring objects entering and exiting its volume. - When "CubeA" enters "Trigger", a script calls an IgnoreCollision between "CubeA" and "Base". **Observation :** - When the "IgnoreCollision" is called between "CubeA" and "Base", "Trigger" fires exit and enter events for the object "CubeB" altough it didnt move at all. It reacts as if "Trigger" (children of "Base") was switched off then on again, when it should simply ignore collisions with "CubeA". **Expected Behavior :** - "CubeB" and "Trigger" interactions should not be affected by a command to ignore collisions between "CubeA" and "Base" or its children. ----- I can understand it could be on purpose that ignoring collision from the parent would ignore collision from the children too, but im pretty sure it shouldnt affect events of a child trigger with unrelated objects. Can anyone confirm this is not the intended behavior ? Its quite a problem for me as in the actual project this behavior causes a logic loop that is quite tricky to avoid in a clean way.

Problem passing through bottom of platform

$
0
0
I created a script that checks if any platforms with the pass platform tag enters a collider surrounding the player object. Then I store the platforms in a list and ignore collision between all the parts of player and them if the players lowest point is less than the platforms position and do the opposite if its greater. Problem is it only works sometimes. Even though the players bottom most point is greater than the platform it still falls through it. Here's the code I use for it in update. //run through all plats to see if collision with them should be ignored or not foreach (Collider2D plat in plats) { //if bottom most point is higher than highest point of plat if ((bmllp > plat.transform.position.y && gi == false) || (bmllp < plat.transform.position.y && gi == true && GetComponentInParent().velocity.y >= 0)) { //dont ignore collision between all parts and plat foreach (Collider2D p in parts) { Physics2D.IgnoreCollision(p, plat, false); } } else { //ignore collision between all parts and plat foreach (Collider2D p in parts) { Physics2D.IgnoreCollision(p, plat, true); } } } I think it might have something to do with the platform being too thin, since when I increase the platforms size the desired result seems to be more consistent. But I would prefer to keep the platform thin, any advice on what to do would be appreciated.
Viewing all 148 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>