# Ray --> SetLimit(vector3f point) method doesn`t work

I use ray for collision detect.

here is my source code.

[java]

private Ray PassPointRay = new Ray();

private Ray PassPointRay2 = new Ray();

Vector3f StartPoint = new Vector3f(-5f, 0.4f, -15);

Vector3f EndPoint = new Vector3f(5f, 0.4f, -15);

System.out.println("Distance " + StartPoint.distance(EndPoint));

PassPointRay.setOrigin(StartPoint);

PassPointRay.setDirection(EndPoint.subtract(StartPoint));

PassPointRay.setLimit(StartPoint.distance(EndPoint)); // ??

[/java]

In this code, setLimit method doesnt work. i wonder why only this method doesnt work.

Who use this method ?

I tried using this a ways back with the same results. The ray just kept goingâ€¦ and goingâ€¦ and goingâ€¦ ignoring the distance limit.

Not sure if this is â€śworking as intendedâ€ť or a bug.

yesâ€¦;; then i can`t use this ;;;

Is there any other way to limit ray distance?

Maybeâ€¦ there is nothing â€¦;?

I use limits with rays all the time.

How do you know it isnâ€™t working?

Note: you are providing an invalid direction since it isnâ€™t normalizedâ€¦ so the actual length of your ray is sort of actually 100.

@pspeed said:
I use limits with rays all the time.

How do you know it isn't working?

Note: you are providing an invalid direction since it isn't normalized... so the actual length of your ray is sort of actually 100.

I test this method by VehicleControl.
Collision results set when VehicleControl didn`t pass among two point. So i can know this method doesn`t work...
'normalized' means changing their vector's size to unity size. How it can be a problem?
I can`t understand how can i fix my source code.

Direction should be a unit vector. You are setting your direction to:

PassPointRay.setDirection(EndPoint.subtract(StartPoint));

Which is definitely not a unit vector (since it is 10 units long).

You need to normalize the direction vector before setting it.

1 Like

Thank you for your help ^^.

I can understand this problem!

1 Like