Adding some camera movement

I have added some camera movement. Its not perfect but looks pretty cool. It moves around trying to keep both players and the ball in the frame. Could probably do with some zoom.

The following script was added to the Camera node:

extends Camera

onready var player1 = get_tree().get_root().find_node(“Player1”,true,false)
onready var player2 = get_tree().get_root().find_node(“Player2”,true,false)
onready var ball = get_tree().get_root().find_node(“Ball”,true,false)

const Z_OFFSET = 12
const NUMBER_TARGETS = 3

var average_translation = Vector3()

func _process(delta):
move_to_average_position()

func move_to_average_position():

# get average position of players and ball	
average_translation = player1.translation + player2.translation + ball.translation
average_translation /= NUMBER_TARGETS

# restore the height so the camera does not go up and down
average_translation.y = translation.y

# apply an offset to keep the camera in the foreground
average_translation.z += Z_OFFSET

# move camera
translation = average_translation

Very cool! Loving the addition!

Privacy & Terms