- Home /
Making a 2D line?
Hey everyone,
I want to see if I can make a line when the user touches the screen on their phone and have two colliders that detect the start and end point.
Here is what I have in mind:
So I want the user to press on the semi-circle on the left and then pull the line down to the right semi-circle.
Can someone help? I really cant seem to think of a way to approach this one?
Cheers,
you could use a line renderer and configure it with two points. the first is always the center of the first collider object and the second gets updated with the finger position.
or you have a gameobject with a quad $$anonymous$$esh and renderer childed to an empty gameobject offset by .5f, have the parent positioned at the first collider, have it look at Vector3.forward, while the up vector used is towards the finger position and scale it by the distance between finger and collider.
Hey thanks for your reply,
But do you reckon I could add a collider to it so that it debugs a message that says it has hit the second semi-circle?
Can you add a collider to the line renderer so that the ball understands it has been hit?
If you could reply, that would be great.
Cheers
afraid not, the line renderer consists only of positions. it does not even need to start at it's own transform position. But what you could do is attach colliders to the semi circles. because your finger reaches them indefinitely. you can use raycast to check if you hit them
Cheers Hexagonuis.
I will try it out and let you know how it went.
Thanks.
Your answer
Follow this Question
Related Questions
Change shape of object upon collision 1 Answer
Run some code just after physics is calculated 1 Answer
Size and Position of BoxCollider 2 Answers
Once more with the Aspect Ratio's 1 Answer