Top down shooter camera follow cursor

Posted By: Altarius

Top down shooter camera follow cursor - 01/09/15 06:45

Hi,

I'm facing a problem that I can't seem to solve. I want the camera to follow the mouse cursor, but the player character to remain visible. So the camera can't go a certain distance away from the player.

like in this game -->game

anyone can help whit this plz?
Posted By: 3run

Re: Top down shooter camera follow cursor - 01/09/15 11:17

search in my older topics (which were created by me), there I was asking for the same thing, idea how to keep camera between player and mouse cursor.
Posted By: txesmi

Re: Top down shooter camera follow cursor - 01/09/15 12:16

Hi,
you will need to substract the screen center to the mouse position, scale the resulting vector to your taste and place the camera in the point resulting from the sum of the player position and said vector.

Code:
camera->pan = 0;
camera->tilt = -90;
camera->roll = -90;
...
vecMouse.x = mouse_pos.x - ( screen_size.x / 2 );
vecMouse.y = ( screen_size.y / 2 ) - mouse_pos.y;
vecCameraOffset.x = player.x + vecMouse.x*0.8;
vecCameraOffset.y = player.y + vecMouse.y*0.8;
camera.x += (vecCameraOffset.x-camera.x) * time_step * 0.1;
camera.y += (vecCameraOffset.y-camera.y) * time_step * 0.1;



Salud!
Posted By: Altarius

Re: Top down shooter camera follow cursor - 01/09/15 16:06

Thx a lot guys.

Work like a charm =)
Posted By: txesmi

Re: Top down shooter camera follow cursor - 01/10/15 11:44

Happy to help!
© 2024 lite-C Forums