0
Answered

Player collision with tag?

CJWorkshop 5 months ago in Game Creator updated by Einar 5 months ago 12

Hey all,

I am very new to unity itself, so this may seem like a silly question, but how do I make the player respond to colliding with an object that has a certain tag on. I have some sand blocks and want the player's movement speed to decrease when he collides with them. 


I have put collectables in the game and have made the character respond to them by using triggers, but is it possible to make him respond to a game object that has a tag on?

Thanks

Unity version:
Game Creator version:

There is a Trigger "on collision enter with Tag". You can use that to trigger an Action.

Click on Change Trigger, it is under Object menu.

Hope this helps.

Thanks so much and for the quick reply. I got it working now :)

Excellent, Well done.

For some reason, it only works when I use "when tag enters" and not when I use "on collision enter with Tag" 


I think I need the collision one to work otherwise I have issues when I move along the sand, as there are many sand objects next to each other. Any ideas?


Thanks

I haven't used this trigger, but as I understand it, you need a collider on the tag object from memory.

"Detects when an object with a certain tag enters the Trigger's Collider area"

You may even need to set the collider to "is Trigger".

You will need to experiment which way around this will work for you ie: trigger collider on player or object, and the tag on the other.

Hmm i tried it with a mesh collider and then a box collider, both with triggers on, but it didn't work.

Under review

Strange, as that should be working. Would you mind sharing some screenshots so we can see where the problem is?

+1

I tested this, it works fine. Must be the way you have it set up. I did this:


On all objects that I wanted to see a collision, I added a tag (the same tag, in my case I added Cylinder - you have to create a new tag by clicking Add Tag).

Then on the Player, I added the Trigger "on Tag Enter" and set the Object with Tag to be Cylinder. 

On the trigger, I added an Action to Display a Debug Message.

I also increased the Trigger from Radius from 0.5 to 1, so the Player did not have to hit the object, just come close.


Under test, the each time the player walked up to or even ran past a Cylinder, the debug message displayed.


Hope this helps.

Thanks. I used the "on tag enter" in the end and got it working properly. For some reason the "on collision enter with tag" does not work for me. Here are some screenshots of the "on collision enter with tag" set up.

I also tried clicking convex and is trigger in the sand box panel, but that makes my character fall through it. 

I have what I need working now, but I am interested in why the "on collision enter with tag" set up isn't working for me. 

Answered

All Triggers that have the "Collision" name (and thus, their icon is red) require colliders to be unmarked from "is Trigger". This, despite not liking it, is a standard in Unity (see https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter.html and https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionEnter.html).

Also, see the collision action matrix on this page https://docs.unity3d.com/Manual/CollidersOverview.html for a more indepth breakdown of exactly which combinations cause a collision or trigger event.

Most likely it's because collider-events needs properly setup rigidbodies on the objects. Unfortunately I am not very experienced with the collision-logic of Unity, so I cannot help any further.