So I'm trying to have the camera get pulled in the direction of the mouse, but stop at the border of the screen. It works, somewhat, but in the wrong direction. Adjusting the camera scale doesn't seem to affect it. Some help would be very much appreciated!
Video Example: https://streamable.com/zfqeur
Notice how the camera moves towards the sides. It moves down as well, but only when it's towards the bottom-right.
Camera script (should be unrelated but just in case):
This script assumes that the zoom.x and zoom.y are always the same.
var zoomfactor = 0.75 # < 1 = zoomin; > 1 = zoomout
var transition_time = 0.25
maxzoom = zoom.x
minzoom = maxzoom * zoom_factor
transitioncamera(Vector2(minzoom, minzoom), newoffset)
transitioncamera(Vector2(maxzoom, maxzoom), newoffset)
func transitioncamera(newzoom, newoffset):
if newzoom != currentzoom:
currentzoom = newzoom
$Tween.interpolateproperty(self, "zoom", getzoom(), currentzoom, transitiontime, Tween.TRANSLINEAR, Tween.EASEINOUT)
$Tween.interpolateproperty(self, "offset", getoffset(), newoffset, transitiontime, Tween.TRANSLINEAR, Tween.EASEIN_OUT)
The main code I'm using to move the camera:
mouseoffset = (getviewport().getmouseposition() - getviewport().size / 2)
camera.position = lerp(Vector2(), mouseoffset.normalized() * 250,
mouseoffset.length() / 1000)
Code for zooming in camera (just in case):
$Camera2D.zoomin(position - $Camera2D.getcameraposition())