Hi,
I’am using rendercam by ross grams. I get the cursor position and rotate player towards it. It works on default cam. But when I started using rendercam, I started to get completely different cursor position values and thats why rotation towards cursor fails. How can I fix this?
Thanks.
Can you show your code? What do you have that works with the default camera and what do you have that does not work with Rendercam?
on_input function gives the cursor’s x and y values (action.x and action.y). When I use rendercam action.x and y is not same as cursor’s position anymore. For x it is like cursor.x + 640 and for y it is like cursor.y + 360.
OK, that’s probably because Rendercam shows a view centered on the camera position, instead of based on the bottom right corner. Rendercam doesn’t (can’t) change what you get from on_input, it just moves the view.
Action.x and action.y are not world coordinates, they only tell you where the cursor is within your window. With the default settings they just happen to match up with world coordinates. If you move the camera or resize the window they will not. With Rendercam, if you want to get the world position “underneath” the mouse cursor, do:
-- in on_input
local mouse_world_pos = rendercam.screen_to_world_2d(action.screen_x, action.screen_y)
This should give you the correct position no matter how you move, rotate, or zoom the camera, or change the window (for 2D games, for 3D there are other functions). Note: make sure you use action.screen_x, action.screen_y, NOT action.x, action.y.
4 Likes
Thank you for detailed answer and this amazing asset rendercam. It helps a lot 
4 Likes