# CollisionRay, CollisionLine, CollisionSegment, CollisionParabola

Can anyone tell me the use and some examples of the Collision Solids mentioned in the title?

Their uses areâ€¦ well, what uses you come up with for them!

Perhaps it would be more helpful to compare and contrast them:

To start with, let me mention how theyâ€™re the same: Theyâ€™re all, essentially, linesâ€“that is, they detect the intersection of a line with whatever other collision solids may be present.

Now, how they differ:

• A CollisionLine more or less what it sounds likeâ€“a line extending off into infinity in either direction. As a result, it will detect things anywhere on that line, again in either direction.
• A CollionRay is pretty much the same, except that it only detects things in one directionâ€“what one might think of as â€śfowardsâ€ť. Nevertheless, in that direction it detects things off into infinity.
• CollisionSegment is again similar, but is even more limited: it only detects things between a start-point and an end-point; any objects beyond those points will not be detected.
• And finally, a CollisionParabola is pretty much like a CollisionLine, except that instead of a straight line, it forms a parabola.

If youâ€™re still struggling to come up with uses for them, then perhaps theyâ€™re simply not yet useful to you.

If youâ€™re wondering which fits your purposes, perhaps consider the effects that I gave above: Do you want to detect things in either direction? Or merely as far as possible in one direction? Or only within a very specific range? Is a straight line appropriate to your purposes, or would a parabola fit better?

OK I understand. They basically the geometry shapes we learnt in school. But how do you construct a parabola?

[Edited]

So basically anything on the line will be colliding, right?
Can it be used like a CollisionCapsule to block players too?

Pretty much, yes!

Iâ€™ve honestly never used a CollisionParabola that I recall, so Iâ€™m not sure. Looking at the API, it seems that you construct a Parabola object, then feed it two end-points along the course of the parabola.

Exactly.

(As mentioned previously, if you just want the first collision, then a CollisionHandlerQueue offers the ability to sort the collision-entries from first to last. Otherwise, you might iterate through the collision-entries and find the nearestâ€“but that, I suspect, will be slower.)

Hum. Theoretically, yes. But if you mean to use it as â€ślevel geometryâ€ť then I donâ€™t know how easy it would beâ€“I donâ€™t know offhand whether youâ€™d get a push-response from one of these when using a CollisionHandlerPusher.

You could get collision-events from a CollisionHandlerEvent, but then you might have to implement the response to those eventsâ€“stopping the player and pushing them out of the â€śwallâ€ťâ€“yourself.

You can of course use a ray or suchlike to detect nearby surfaces and thus stop the player, but that tends to be less effective than using a sphere, I think.

I saw the API. the construction for a parabola says it needs 3 arguments. I think the 2 float arguments are the main ones. But what about the first argument of type LParabola? what should I pass here?

As it says: A Parabola object. To elaborate: Note that, in the API, for that parameter it says â€śparabola: LParabolaâ€ť. The second part of that indicates the type of the parameterâ€“in this case an object of type â€śLParabolaâ€ť. If you click on that, you should be taken to the API page for that class, which should give you more information on what it is and how one constructs it.

The original purpose of CollisionParabola is to implement aiming of a thrown object (like a cannonball) in games, if you want to show an aim arc and need to give feedback to the player about what or where it will hit, like so:

Of course, if you can find another use for it, then more power to you!

1 Like