#you added it from here yes?
1 messages · Page 1 of 1 (latest)
I still can't get the collision detection to work. My setup is:
- Character gameObject - RigidBody 2D
- Created 3D > TextMeshPro
- Added BoxCollider to the TMP and sized it to be the same size as the text bounding box
- Checked isTrigger
- Added a tag to the character
- 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
If you're doing 2D game then you need 2D colliders, and you cannot use that event since its for 3D
also this implies your text had collider set to trigger
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?
does it have rigidbody ? the text move or not ?
you should explain what this game mechanic is supposed to do because I still don't know lol
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.
does player have rigidbody ? put the OnTriggerEnter2D on it , then put is Trigger on collider of text object
I see you did write player had rigidbody so yeah should work
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
why is player trigger
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?
can you show the collider yout put on the text object .
also dont put player as trigger
Sure
Should the text have isTrigger on then?
yes
is this a 2d box collider ?
show inspector for this text object
On the text, it's the 3D box collider
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
Ah that makes sense, it works now, thanks so much, I really appreciate your help!