Strange spotlight direction

Hi,

The PG
https://playground.babylonjs.com/#20OAV9#9197

(please click run to make it happen)

The issue:
When creating a spotlight, we give a position and a direction.
I expected the direction vector to be a point of the middle line of the cone.

Instead, It doesn’t seem to be always the case.

I created a laser-like spotlight to show the issue.
The b0 cube is the start of my spotlight, and the b1 represents the end.

I should always have a red dot on my b1 cube (the “to” vector in the PG), but instead, the direction show unpredictable and the spotlight doesn’t follow it exactly, showing no light on b1.

Now, please interchange laser_type and larger_type: the result is not properly centred.

I cranked the intensity up to make sure it wasn’t related.

I need a very precise way to create light paths.

In my scene, at scale, it is really off.

You can disable/enable the “ground” box (didn’t bother to change the naming), to make sure that it is not physics at play here.

How may I deal with this situation? What did I do wrong? Isn’t the direction vector to be understood like “the centre line of the cone should pass by that point exactly”? Is it caused by rounding?

thanks !

The direction you want to use is to - from, not to:

2 Likes

Thanks Evgeni :+1:

that’s nice, but I am in the dark: why do I need to substract?

The direction should not be understood as a “point in space where the line pass” but a real direction vector, like, say, a normal, needing to be adjusted to the starting point to give the correct result ?

That would explain everything, but I need a confirmation :innocent: :slight_smile:

Yes, a direction (a vector in maths) is a difference between two points, not a point. It has no starting point. For eg, a (2,3) vector in 2D means you must go 2 units in the +X axis direction and 3 units in the +Y axis direction. So, if you start at position (4,5), you will end up at (6,8).

1 Like

Thanks Evgeni for your definitive answer :slight_smile:

1 Like