Multiple scripts to one main node
Asked Answered
J

7

0

Hello, this is my first post so take it easy.

I got some problems that I dont know how to solve.

Starting from the very beggining.

I have 2 scenes, one is just a test world as seem below:

And my player scene also seem below:

Here is the thing, there is 2 cameras attached to the 3d model, first and third person, at first my player code was just one single script with somewhere around 150 lines doing basically player control, camera control, etc. When told to make things simple by putting a FPS script into the FPS cam, TPS script to TPS and so on my code just broke and only boots up in FPS mode without player control.

I also have no idea how to instance what I've already got and to control the player and camera from different scripts.

extends Node3D

@onready var player = load("res://scene/player.tscn")

func _ready() -> void:

player.tps_camera.set_current(true)

   func _process(delta: float) -> void:
      #instance player.tscn here
      print("test")

How am I supposed to make player scene get all this info?

Joselyn answered 20/11, 2023 at 11:8 Comment(0)
H
0

Joselyn Well, my first advice would be: if this whole setup and game is too complicated for you right now (which is totally fine) then do something simpler first. For example make a 3D game/prototype where you only have one camera. Or make a simple 2D game first to learn how to couple your scenes and pass information between them. Learning the fundamentals in an already complex 3D setup could be a bit much for a first starter project. You can always come back to this.

How am I supposed to make player scene get all this info?

What info do you mean?

Heathendom answered 20/11, 2023 at 11:25 Comment(0)
J
0

Heathendom

Well, I already got the FPS and TPS working fine just before I moved things around.

This is how things are supposed to work. But I cant find anything related on the documentation or even in the internet (maybe I'm just searching it wrong)

How am I supposed to make player scene get all this info?

How to make the player.tscn spawn in testWorld.tscn with all the mechanics already programmed

Joselyn answered 20/11, 2023 at 14:51 Comment(0)
C
0

Joselyn How to make the player.tscn spawn in testWorld.tscn with all the mechanics already programmed

Just drag and drop the player scene into world scene. If you want to spawn it at runtime use PackedScene::instantiate().

Btw imho it's better to keep camera rigs outside of player scene.

Culpable answered 20/11, 2023 at 14:58 Comment(0)
J
0

Quick update:

It loads up the menu just for debug reasons, every button besides start has a print("button name just pressed")

The problem now it is returning me this error


Joselyn answered 20/11, 2023 at 15:1 Comment(0)
J
0

Culpable

Can you explain me more?

Joselyn answered 20/11, 2023 at 15:1 Comment(0)
C
0

Joselyn Can you explain me more?

Introductory chapters in the official documentation can explain you much more 🙂 Here, it's better to ask specific questions.

If you have the world scene and the player scene, just drag the player scene into world scene and the player scene will appear as an instance in the world scene. All scripts inside this instance will work when you play the project.

Culpable answered 20/11, 2023 at 15:8 Comment(0)
H
0

Joselyn The function should be called change_scene_to_packed().

Heathendom answered 20/11, 2023 at 15:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.