x


Is there a way to check collision for a line rendered by a line renderer?

I rendered a Line in the worldspace and would like to make the player follow the line using touch input. Then I want to check how accurate the player is. Is there a way to make raycasting on the line? The line renderer has a bounding box, but the box size is the size that covers the whole line set, I need a point precision on the collision check. Can anyone help on this? Any suggestion to implement this?

more ▼

asked Jan 13 '11 at 10:15 AM

Eddie 2 gravatar image

Eddie 2
29 5 6 10

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

A simple point-line distance check may work better than collision detection in this case.

A pseudo-code example:

if DistanceFromPlayerToLine < Tolerance
    // Player is following line correctly.
else
    // Player has strayed too far from the line.

I don't have any references for 3D distance equations handy.

If your game is 2D:

Here is a good reference for 2D point-line distance.

For C# code, you can search the code in this google code project for "GetPointSegmentDistanceSq" or "GetPointLineDistanceSq".

more ▼

answered Jan 13 '11 at 04:45 PM

SteveFSP gravatar image

SteveFSP
1k 8 13 29

(comments are locked)
10|3000 characters needed characters left

Instead the line renderer use raycast in your scripts, then use the line renderer with the same coordenates of raycast just to show the line.

more ▼

answered Jan 13 '11 at 12:37 PM

Borgo gravatar image

Borgo
998 9 13 25

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2490
x179
x132
x108

asked: Jan 13 '11 at 10:15 AM

Seen: 1506 times

Last Updated: Jan 13 '11 at 10:15 AM