简体   繁体   中英

Unity 2D line collider

I try to do the following: I have a point A at -4x-4y and a point B at 4x 0y. I want to make a colliding line from position A to position B.

I tried to do it with a linerenderer but I can't get the line to collide with my other 2d objects.

在此输入图像描述

My other tought was to calculate the center of the points and the rotation and do it with a box collider but that seems to be really complicated and hacky.

Is there a simple way to achieve this?

Thanks in advance

您可以使用PolygonCollider2D ,它会自动为精灵创建碰撞器,如果您对结果不满意,可以通过单击检查中的编辑碰撞器来编辑它,或者使用Unity的API

I think you must have a Rigidbody2D attached with your other 2D object. Then this will work 100%. You can use any collider it doesn't matter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM