- Home /
how to add Rigidbody and Collider to line renderer
I want to make an application that let you draw anything using line renderer or any another method like in brain dots game where we make something to join both balls i search how to do this in unity but i got only how to draw circles or lines using unity but i also want to attach it Collider and Rigidbody in Unity 2D please help me.
Answer by Lichemperor · Sep 10, 2016 at 08:52 AM
I'm not sure what platform/device you're targeting, but what you may want to look at is following the user's current cursor position with a GameObject with a line renderer component.
You could choose to use something like the following code to get the user's current position:
RaycastHit2D hitInfo = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (hitInfo.collider != null) {
int x = Mathf.FloorToInt(hitInfo.point.x);
int y = Mathf.FloorToInt(hitInfo.point.y);
currentPos = new Vector3(x, y, y);
}
currentPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
I suggest providing more information to your question: nobody wants to tell you exactly how you should program your idea.
I got this use following steps 1) uncheck use world space of LineRenderer component 2)create empty gameObject and add Rigidbody component to it 3)In LineRenderer Script just assign parent of gameObject to the empty gameObject
Your answer
Follow this Question
Related Questions
Static Colliders in the 2D Engine in Unity 5 1 Answer
Weird behaviour after Collision? 0 Answers
Using child colliders with rigidbodies/joints in 2D 0 Answers
2D Rubber hands (Weird question) 1 Answer
Is it possible to have continuous collision detection with dynamic points on Edge Colliders? 0 Answers