Ignore colliders

Hi,

Is there for the grid graph generator to ignore some colliders?
I’m building a TD game and the towers have a big collider as trigger in them to detect nearby enemies, I would like the grid to only take into account another smaller collider which is in a sub-component of the towers.

Thank you.

Hi

You can use the layer mask in Grid Settings -> Collision Settings -> Mask.

That was quick. :slight_smile:

I thought that would be the place , however placing layers in Collision Settings -> Mask only seems to make the area around the objects in the layer larger.
I read somewhere there was a bug with this, could that be the case? I dowloaded the package 2 days ago.

Thank you

I mean the unwalkable area.

The change needed to be done in the height mask, not the collision. If anyone comes across the same problem.

1 Like

Ah, yes. I should have mentioned, you also have to make a change in the height mask. Great that you managed to solve it though.

Np, thank you!
Just a note, I think it would make sense if colliders in trigger mode wheren’t accounted by the height dettection.

That is controlled by the unity physics settings. Project Settings -> Physics -> Raycast Hits Triggers.

Ah nice to know that! Thank you!

Sorry, I am having issues with this and was hoping for some help! Using Unity 4.2.

I have a single gameobject with two colliders; one box (small), one capsule (large). The capsule has isTrigger == true. RaycastsHitTriggers == false in the physics engine. The gameobject has layer == building.

Both GridGraph CollisionTesting and HeightTesting includes the building layer.

When I scan, the graph registers hits on both colliders.

Any idea what I am missing?

Ah, I figured it out. The RaycastsHitTriggers only affects raycasts (obviously), not SphereCasts, LineCasts, or CapsuleCasts. This makes sense, but reduces the casts I have at my fingertips.

Hi NuneShelping,
I have the same configuration, one gameobject with a sphere collider (trigger) and a box collider (not a trigger), I tried few things suggested above but I still have the issue.
What do you mean by SphereCasts?

Thanks

Physics.SphereCast is what he is referring to. It is among other things used for the obstacle detection by the A* Pathfinding Project.

I see, could you please give me some hints on how and where to disable it?

Also, is this the best solution or should I have a parent object with two childs, one with the box collider and one with the sphere collider (trigger) and have the masked layer on the box collider child only?

Thank you

Hi

Try to set Project Settings (in unity) -> Physics -> Raycast Hits Triggers to false. That will make the A* Pathfinding System (and anything else using Physics.SphereCast to ignore triggers).

Hi Aron, thanks for the suggestion but that stops NGUI from functioning. I found another way of dealing it… basically adding an empty object with a collider and a masked layer.
Thanks!

Just for anyone looking for a solution to this I will add what I have done, as described I have created a child gameObject with the trigger on that, and set a trigger layer in the mask.

I then added the following code to help with the trigger:

using UnityEngine;
using UnityEngine.Events;
	public class TriggerHandler : MonoBehaviour
	{
		public bool triggerForPlayerOnly = true;
		public UnityEvent onTriggerEnterEvent;
		public UnityEvent onTriggerStayEvent;
		public UnityEvent onTriggerExitEvent;

		private Collider2D _collidedObject;


		private void OnEvent(UnityEvent _unityEvent_)
		{
			_unityEvent_.Invoke();
		}

		private void OnTriggerEnter2D(Collider2D _other_)
		{
			if (triggerForPlayerOnly && !_other_.CompareTag("Player")) {
				return;
			}

			_collidedObject = _other_;
			OnEvent(onTriggerEnterEvent);
		}

		private void OnTriggerStay2D(Collider2D _other_)
		{
			if (triggerForPlayerOnly && !_other_.CompareTag("Player")) {
				return;
			}

			_collidedObject = _other_;
			OnEvent(onTriggerStayEvent);
		}

		private void OnTriggerExit2D(Collider2D _other_)
		{
			if (triggerForPlayerOnly && !_other_.CompareTag("Player")) {
				return;
			}

			_collidedObject = _other_;
			OnEvent(onTriggerExitEvent);
		}

		/// <summary>
		/// Gets the Collider2D from the last trigger.
		/// </summary>
		/// <returns>Collider2D</returns>
		public Collider2D GetCollider() => _collidedObject;
	}

Just place this on the trigger gameObject and then place any functions in the events within the inspector.

1 Like