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):
extends Camera2D
This script assumes that the zoom.x and zoom.y are always the same.
var currentzoom
var minzoom
var maxzoom
var zoomfactor = 0.75 # < 1 = zoomin; > 1 = zoomout
var transition_time = 0.25
func ready():
maxzoom = zoom.x
minzoom = maxzoom * zoom_factor
func zoomin(newoffset):
transitioncamera(Vector2(minzoom, minzoom), newoffset)
func zoomout(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)
$Tween.start()
Player Script:
The main code I'm using to move the camera:
func process(delta):
mouseoffset = (getviewport().getmouseposition() - getviewport().size / 2)
camera.position = lerp(Vector2(), mouseoffset.normalized() * 250,
mouseoffset.length() / 1000)
Code for zooming in camera (just in case):
if Input.isactionpressed("zoomin"):
$Camera2D.zoomin(position - $Camera2D.getcameraposition())
if Input.isactionpressed("zoomout"):
$Camera2D.zoomout(Vector2(0, 0))