Godot Version
`godot 4.4
Question
`i have a mesh that looks at the player with this code look_at(player.global_position) but the problem is there is no rotation limit so how can i set that up ?
`godot 4.4
`i have a mesh that looks at the player with this code look_at(player.global_position) but the problem is there is no rotation limit so how can i set that up ?
Depends on what you mean by rotation limit.
How do you define this limit? Is it in relation to its initial forward facing orientation or some other constraint. It would help if you could further describe your intended functionality.
If you want to limit the camera’s rotation to be contained within some angles, I usually do it like that. It’s easier to split rotation of 2 axis to 2 separate nodes, otherwise you have to deal with gimbal locking and all that fun stuff.
This is the piece of code that goes to your surveilance camera.
extends Node3D
@export var target: Node3D
@export var base: Node3D
@export var pivot: Node3D
var min_angle_y: float = -PI / 6
var max_angle_y: float = PI / 6
var min_angle_x: float = -PI / 6
var max_angle_x: float = PI / 6
func _process(_delta: float) -> void:
base.rotation.y = clampf(base.transform.looking_at(target.global_position).basis.get_euler().y, min_angle_y, max_angle_y)
pivot.rotation.x = clampf(pivot.transform.looking_at(target.global_position).basis.get_euler().x, min_angle_x, max_angle_x)
This is the scene structure.
#Edit: simplified the formula to use transform and applying the value directly.
thank you
thank you, i found a solution