|
|
|
 |
Attention |
Topic was automatically imported from the old Question2Answer platform. |
 |
Asked By |
classy |
I’m trying to figure out how to switch the camera location to a different room when the player enters it, the camera is in a static position for each room and will switch whenever the player enters a different area, however I can’t seem to figure out how to do this. someone help pls.
1 Like
|
|
|
 |
Reply From: |
GlitchedCode |
Well first you would need to know when the player has entered a room, so something to give off a signal for example. One option here could be an Area that emits a signal . This signal would then need to be connected to something, maybe a game manager or the camera itself. When the player body enters the area and the signal is emitted, set the position of the camera. You can do this directly by tweaking its position property or tween it to have a smooth transition be it fast or slow to the new position.
This would be the basic idea to complete this objective, though keep in mind this may only be one way to obtain this.
i see. but how would i do that?
classy | 2023-07-05 07:12
1 Like
|
|
|
 |
Reply From: |
Griefchief |
Create a scene with following chilren nodes:
- Area3D (TopLevel Node)
|- CollisionShape3D (give it a propper shape int he inspector too)
|- Camera3D (Attach an empty script to the camera 3D)
Then next:
- Click on Area 3d node in the scene view
- Click on the Inspector’s “Node” tab (all the way to the top right in Godot’s UI) and attach a body_entered signal to the Camera3DNode, the name of the function will be similr to
func _on_node_3d_body_entered(body):
....if body.is_in_group("player"):
........self.make_current()
-
Find your player node (RigidBody3D or CharacterBody3D) and attach a group to it named “player”. You can do that on Inspector’s “Node” tab, by clickin on the group subtab.
-
Copy paste this setup for every room you have, a camera for every room (all cameras can reuse the same .gd script)
-
Better yet, make this whole setup it’s own scene (.tscn), and then instantiate the scene everywher eyou need it so you don’t need to do 1/4 work over and over and over.
You can then right click on the instantiate scene node in the inspector and select “Editable children” to edit things like Area3D size
(make the CollisionShapes “shape” resource unique dropping it’s “dropdown” menu and choosing “Make Unique” or you’ll edit the shape of every Area3D, Resources are shared between nodes)
Look something like this:


1 Like