Legacy GM Limit camera to in room, but don't just stop it.

Z

zennysquid

Guest
So I am having my camera in between the center of the room and the mouse, but it can go way far out of the room, I have some code that stops it before it goes out of the room but it makes it stop instantly and it looks bad. How would I make it smoothly stop outside of the room? Like have it move less the farther away the mouse is from the center.
Code:
view_xview = lerp(view_xview,mouse_x-(view_hview[0]/2),.05)
view_yview = lerp(view_yview,mouse_y-(view_hview[0]/2),.05)
Above is the code I use for the camera.
 
T

TimothyAllen

Guest
So I am having my camera in between the center of the room and the mouse, but it can go way far out of the room, I have some code that stops it before it goes out of the room but it makes it stop instantly and it looks bad. How would I make it smoothly stop outside of the room? Like have it move less the farther away the mouse is from the center.
Code:
view_xview = lerp(view_xview,mouse_x-(view_hview[0]/2),.05)
view_yview = lerp(view_yview,mouse_y-(view_hview[0]/2),.05)
Above is the code I use for the camera.
You could simply multiply your lerp amount (0.05) by an inverse ratio based on the current distance between the center of the view and the center of the room and the maximum distance you want the view center to stray from the room center. You can exponentially increase both of these distances to increase the rate at which the inverse ratio falls to 0.

PS. Your using view_hview[0] when you should be using view_wview[0]. If you haven't notices this then your view must be square.

EDIT: Also you will need to check if the mouse is on the same side of the view center as the view is to the room center. Otherwise the view could get stuck at the room edges because the ratio would be 0... meaning no lerp.
 
Top