Y
Y
YakutD2019-05-24 22:25:06
C++ / C#
YakutD, 2019-05-24 22:25:06

How to send a ray from the edge of an object?

Hello, we are making a kind of Tetris, and to determine whether the figure can fall further, we use
the following code

RaycastHit2D hitDown = Physics2D.Raycast(transform.position, Vector2.down, 0.5f);
Debug.Log(hitDown.collider.name);

However, the ray returns the name of the shape itself. The collider is a square. Tell me what I'm doing wrong,
I suppose it's in the first argument of the raycast, but I can't figure out how to set the beam to fly out exactly from the edge of the object.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2019-05-25
@YakutD

I'll just leave my opinion here, suddenly it will help you to realize something) - what to do in Tetris check by "probing with a beam" is rather strange.
and how does it cover the options for the horizontal stick? rays from each edge? and if the stick stumbled on the PIK in the middle?
and specifically on the issue of
transform.position - will return you Pivot (Center of the object).
as such, you can set the extreme points separately in the figures, simply by placing a couple of child Transforms, and saving links to them in some kind of container.
If your shapes are a solid custom mesh, then you can also look towards
https://docs.unity3d.com/ScriptReference/Mesh-boun...
to find out the boundary points of the mesh.
well, having learned the points from which you want to send the ray - just substitute from the coordinate instead of transform.position.
if all of the above causes bewilderment and misunderstanding - then the English. and unity tutorials - earn bumps, that is, experience))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question