Trying to create a camera like this game (Nuclear Throne).

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
inJuly
Prole
Posts: 20
Joined: Fri May 01, 2020 9:02 pm

Trying to create a camera like this game (Nuclear Throne).

Post by inJuly » Fri May 22, 2020 6:37 am

Nuclear throne is a topdown 2D shooter roguelike that has a camera which isn't centered on the player. Instead it moves slightly towards the mouse cursor.
screenshot:

Image

So there was this unity tutorial on how one would go about doing it, I didn't follow it but it explains the camera well:

https://www.youtube.com/watch?v=etI-2dHeufc&t=241s

Now, I am trying to create something similar, and I what I do is this :

Code: Select all

camera.setPos((player.pos * 5 + cursor.pos) / 6)
And it works fine. But the issue is when I try to move and shoot, the camera moves in a way that makes it hard to focus on one target.
In Nuclear throne however, the camera looks like it's much more resistive to sudden movement. How can I implement this ?

User avatar
4vZEROv
Citizen
Posts: 90
Joined: Wed Jan 02, 2019 8:44 pm

Re: Trying to create a camera like this game (Nuclear Throne).

Post by 4vZEROv » Fri May 22, 2020 1:29 pm

You can apply some lerp

Code: Select all

    function lerp(a, b, x) return a + (b - a) * x end
    local current_position = camera.getPos()
    local target_position = (player.pos * 5 + cursor.pos) / 6
    camera.setPos(current_position, target_position, 0.1)

Post Reply

Who is online

Users browsing this forum: MadByte and 38 guests