Page 1 of 1

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

Posted: Fri May 22, 2020 6:37 am
by inJuly
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 ?

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

Posted: Fri May 22, 2020 1:29 pm
by 4vZEROv
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)