Detect collision with a Line

Hi,

I know we can’t add physics body to a Line created with newLine(),  but does anybody has a way to detect if another physics object “hits” (collides) with the  line?   :slight_smile:  

Could you use a thin object made by newRect (), instead? (Is it just a two-point line?)

How complex are your other objects? If you only need collision detection (and not response) it might not be so bad.

@StarCrunch,

I use the Line as a visual representation of a “rope” in a rope joint (imagine a rope with a wrecking ball hanging at the end), so yes the rope is always straight in my case even if the “pendulum” swings.  If something touches it, I need to have that detected in my code to do some logic (subtract score, etc.)

Yes, a newRect() can also be used to represent the rope as you cited;  I just have to deal with the necessary coding for its rotation to follow the hanging object, and also the “shrinking” part when the “ball” lands and the structure nears it (ie. like a contracting rubber band). 

I was just thinking if there is a shorter, easier way to detect the collision.   :slight_smile:   Thanks for the feedback.

Could you use a thin object made by newRect (), instead? (Is it just a two-point line?)

How complex are your other objects? If you only need collision detection (and not response) it might not be so bad.

@StarCrunch,

I use the Line as a visual representation of a “rope” in a rope joint (imagine a rope with a wrecking ball hanging at the end), so yes the rope is always straight in my case even if the “pendulum” swings.  If something touches it, I need to have that detected in my code to do some logic (subtract score, etc.)

Yes, a newRect() can also be used to represent the rope as you cited;  I just have to deal with the necessary coding for its rotation to follow the hanging object, and also the “shrinking” part when the “ball” lands and the structure nears it (ie. like a contracting rubber band). 

I was just thinking if there is a shorter, easier way to detect the collision.   :slight_smile:   Thanks for the feedback.