New camera system has been applied!


After messing around with the code of my game, I completely rewrote all of the camera switching codee, as you might remember, a a couple of days ago I found a better way to switch between characters in a test project, this code tho, was extremely limited.

I am using a node called Players, were all of the players (duh) are children of it. Adding a script to the players node, and an extra camera to the parent of Players (the level scene) I only had to use a match statement between every child available, wich was stored in its own variable.

This code was a bit wonky tho, I will share some images. As you can see, I would have to manually add every player to the match statement, and altough it would work, it would be a really bad thing if I wanted to expand it to more, and I dont know I would manage killing players in it, altough maybe i could have solved thatWonky Player switch movement code

I decided to work on a better way and I ended up coming up with this

func switch_player():
    cam.current = true
    can_move = true
    for player in players:
        if player == new_player:
            player.cam_will_be_enabled =true
        else:
            player.cam_will_be_enabled = false
    if current!=null and new_player!=null:
        tween.interpolate_property(cam,"position",current.cam.global_position,new_player.cam.global_position,.3,Tween.TRANS_SINE,Tween.EASE_OUT,0)
        tween.start()
    cam_timer.start()
    timer_started = true

#This timer starts whenever the tween to move the 
#main camera is enabled, as soon as its done, the new player camera is enabled
func _on_SwitchCamTimer_timeout():
    timer_started = false
    if new_player != null:
        new_player.cam.current = true
    current = new_player
    var b = 0
    a=0
    for player in players:
        if player == current:
            new_player = players[a+1 if a < players.size()-1 else b]
        print(a)
        a+=1
    can_move = false

As you can see, this method allows me to change the player cam position and its called by a signal after the Tween is done

Get Swap Die Repeat!

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.