I cannot make this ray to follow my mouse cursor.
It’s always inverse on X axis.
I think that the problem is with my atan function, but since my trigonometry is fairly low, I have no idea how to fix this one.
This is how I calculate radians:
var dx = target.x - center.x;
var dy = target.y - center.y;
var rad = Math.atan2(dx, dy);
Fiddle
The fiddle above doesn’t work in Firefox as FF doesn’t natively support
event.offsetX/Yfor mouse events, I assume your normalization code was cut off when making the minimalistic example but I’ll leave my normalization code here for future reference:Then just pass the jQuery event object to it.
Fiddle