how are you tracking your players position and facing angle?
say player is a table like so :
now im going to assume you lock the camera to render over the player at all times, and that the player is centerd on the screen at 400,300
assume that the torch light is stored under a variable [torch].
now to make the light point at the mouse we simply do :
Code: Select all
local mouseP = {love.mouse.getPosition()}
local angleMouse_toPlayer = math.atan2( mouseP[2] - 300 , mouseP[1] - 400 ) --we use 300,400 as its where the player will render (@{y,x})
--now we set the light to just use the above angle!
torch.setDirection(angleMouse_toPlayer)
now also, if the player iss not at 400,300 at all times (centred) then we use world position but making sure to offset the mouse coordinates with camera offset :
assume the cameras offset is stored under variable [cameraOffset]
Code: Select all
local mouseP = {love.mouse.getPosition()}
local mouseP_offsetByCamera = {mouseP[1]+cameraOffset[1],mouseP[2]+cameraOffset[2]}
-- this should offset the mouses local position to the "world" position.
local angleMouse_toPlayer = math.atan2( mouseP_offsetByCamera[2] - player.y , mouseP_offsetByCamera[1] - player.x )
torch.setDirection(angleMouse_toPlayer)
that should work, as its more or less what ive used in my own code, I included camera offset help too since it sort of got me stuck when i was working with a loose camera in the past.
Note that code above is untested in a actual project or environment and may not work as intended.