Saturday, July 23, 2022
HomeGame Developmentcollision detection - Doing a one-time verify to see if a GameObject...

collision detection – Doing a one-time verify to see if a GameObject is touching a toddler of one other GameObject


I’m making a easy Phrase Recreation in Unity, to assist train youngsters the right way to learn. Within the app, colourful letters might be dragged and dropped onto plain letters. Mainly it is a souped-up matching recreation, much like Infinite Alphabet:

enter image description here

The Plain Phrase has its personal GameObject, and the Plain Letters are organized into Items nested beneath the Plain Phrase. For instance, the Plain Phrase for SHRIMP would have the next hierarchy:

enter image description here

(This extra complicated Hierarchy construction is as a result of my recreation is greater than only a pure matching recreation. However the recreation does have the identical core mechanic as an identical recreation: dragging letters onto different letters, after which when the mouse button is launched… checking for overlap.)

The Plain Phrase itself has a (Kinematic) RigidBody2d element on it, and every Letter beneath it has a RigidBody2d and a Field Collider 2D element.

Mainly when a Colourful Letter is dropped onto a Plain Letter nested beneath the Plain Phrase, it checks the Plain Letters to see if it matches the Colourful Letter.

That is my first time utilizing Colliders, and I am struggling (spent all day studying numerous the collider/rigidibody documentation, and studying code snippets!). Plenty of the scripting examples on the market assume we’re checking for collisions in actual time (e.g. to see if an Enemy object is touching your Participant object, during which case the Participant takes injury).

However I need to ignore all of the real-time collider detection, like On Set off Keep 2D. After a Colourful Letter is dragged and the mouse goes up, I need to do a one-time verify to see if the Colourful Letter is now touching the Plain Phrase… and if that’s the case, which of the Plain Letters it’s touching.

At first I used to be pondering to make use of the Overlap Collider, like this (I am utilizing Visible Scripting).

enter image description here

However then I would want to detect which baby Plain Letter is closest to the Colourful Letter touching it… am battling the fundamentals on the right way to detect which baby object is touching the Colourful Letter.

Is that this method value exploring? Is there one other method to go? If somebody may level me in the fitting course, I might vastly admire it!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments