Godot Version
4.7.2
Question
I got simple 2.5D Platformer with need of camera positioning from side, while there was great solution of snap from @gertenko in other post ( Camera3D - how should I determine to switch to new position? - #2 by gertkeno ) i wonder how could I determine switching of camera based on player position?
How looks this simple level :
Camera positions
4.0, 3.0, 11.0)
(20.0, 3.0, 11.0)
(20.0, 10.0, 11.0)
(26.0, 10.0, 11.0)
(5.0, 10.0, 11.0)
(26.0, 1.0, 11.0)
(13.0, -3.0, 11.0)
(3.0, -3.0, 11.0)
The first is default where player starts.
How could I determine best camera view from player position?
For now I used Area3D with collision shapes
func _on_frame_1_body_entered(body: Node3D) -> void:
if body.is_in_group("player1"):
position = camera_positions[0]
func _on_frame_2_body_entered(body: Node3D) -> void:
if body.is_in_group("player1"):
position = camera_positions[1]
You could check distances, but I think Areas will give more precise control which is probably your goal.
func get_camera_position() -> Vector3:
var shortest_dist: float = player.global_position.distance_squared_to(camera_positions[0])
var shortest_index: int = 0
for i in range(1, camera_positions.size()):
var this_dist: float = player.global_position.distance_squared_to(camera_positions[i])
if this_dist < shortest_dist:
shortest_index = i
shortest_dist = this_dist
return camera_positions[shortest_index]
Suppose we’ve explored the full range of programmatic versus curated content lol
|
|
| Automatic position & transition |
Snapped |
| Manual position, auto transition |
Use closest point |
| Manual position & transition |
Camera volumes |