#you added it from here yes?

1 messages · Page 1 of 1 (latest)

peak trellis
#

I still can't get the collision detection to work. My setup is:

  1. Character gameObject - RigidBody 2D
  2. Created 3D > TextMeshPro
  3. Added BoxCollider to the TMP and sized it to be the same size as the text bounding box
  4. Checked isTrigger
  5. Added a tag to the character
  6. Attached a script to the TMP that has an onTriggerEnter
private void OnTriggerEnter(Collider other) {
        if (other.CompareTag("Player")) {
            Debug.Log("in choice onTrigger");
        }
    }

What am I missing?

CC: @elder tundra

wet grotto
#

also this implies your text had collider set to trigger

peak trellis
#

I see. I also tried setting the onTriggerEnter2D on the character object instead, and adding a tag to the text to detect collision. Is that what you meant?

also this implies your text had collider set to trigger
Yeah, I did turn the isTrigger flag on. Should I not have it on?

wet grotto
#

you should explain what this game mechanic is supposed to do because I still don't know lol

peak trellis
#

No, the text doesn't have rigidbody. I don't want it to be affected by gravity

The entire use-case is:
I want a character component that can move and jump. I have a question mark 2D object. I am detecting the player's collision with the question mark upon which, I want to display the question and the choices. The player should then jump on one of the choices to choose an answer, and the game displays whether it was the correct answer or not. It's a quiz type game.

wet grotto
#

I see you did write player had rigidbody so yeah should work

peak trellis
#

Yes, the player has rigidbody.
And the player also has onTriggerEnter2D. The text has the isTrigger enabled too, and it doesn't work still.

I have a similar setup between the player and the question mark and that works fine, so I'm not sure why this won't.

To summarize your suggestion, is this correct:

  • Have Collider and isTrigger enabled on text
  • Add a tag to the text
  • In the player script, have an onTriggerEnter2D to detect collision with the tag

If this is correct, this is the setup I have and it doesn't work

peak trellis
#

The player is the 2D object. If we can only use onTriggerEnter2D which would be in the player script, shouldn't we have isTrigger on the player as well?

wet grotto
peak trellis
#

Sure

Should the text have isTrigger on then?

wet grotto
#

is this a 2d box collider ?

#

show inspector for this text object

peak trellis
#

On the text, it's the 3D box collider

wet grotto
#

no why is it a 3D box

#

thats why its not working

#

2D physics and 3D physics don't interact with eachother

#

it should be a 2D box collider

peak trellis
#

Ah that makes sense, it works now, thanks so much, I really appreciate your help!