Define the limits of a 3D camera

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Lavistios
:warning: Old Version Published before Godot 3 was released.

In Godot, it seems that only the 2D camera has the option “Limit” allowing the camera not to follow the Player all the time according to the values of “Limit”.

But the 3D Camera does not have this tab and does not stop following the Player permanently.

Solution ideas?

(Yes, I am a beginner and I am lost.)

:bust_in_silhouette: Reply From: eons

First, separate the camera from the player, and make it follow the player with a script.

Then just stop moving it when reaches some fixed values.


More dynamic ways can be attaching the camera to a CollisionObject that moves in its own allowed zones trying to follow the player (blocked with bodies ignored by the player).

Hi,

Thank you for your reply. After watching a few tutorials, I realized how easy the solution to this question was. Thanks to my research, I was able to create a script that works perfectly. Thanks again for your time and patience!

extends Camera

# Max and Min in the x axis
export var xMax = 0.0
export var yMax = 0.0  
# Max and Min in the y axis
export var xMin = 0.0
export var yMin = 0.0
# Smooth Camera Trigger and SmoothSpeed value
export var Smooth = false
export var SmoothSpeed = 0.125

func _ready():
    set_process(true)
    pass

func _process(delta):

var Target = get_node("/root/World/Main Player").get_translation()
var Own = get_node(".")

var Start = get_node(".").get_translation()

var Clampx = clamp(Target.x, xMin, xMax)
var Clampy = clamp(Target.y, yMin, yMax)
var Clampz = Own.get_translation().z

var All = Vector3(Clampx, Clampy, Clampz)

if Smooth == false:
	get_node(".").set_translation(All)
if Smooth == true:
	var Lerp = Start.linear_interpolate(All, SmoothSpeed)
	get_node(".").set_translation(Lerp)

Lavistios | 2017-10-28 13:04