#How could I change characters?

1 messages · Page 1 of 1 (latest)

jagged plume
#

Hello, I am working on a 3d game where you control a boat until you find treasure and then you should switch to the first person character where you swim to collect the treasure. I can do it by just loading another scene when you find treasure but I would like if it was all in one scene.

TLDR: Switch from one character to another

mighty flume
#

My first approach would be to create a autoload script that has a currently_controlling variable.

Inside the controller for the boat/person check that the currently_controlling is itself before moving based on any inputs

Use signals to update what currently_controlling is set to with a setter function (and if needed move the camera on signal commands too)

timber steeple
#

I use a "controller" pattern for this. Instead of the traditional "player" object that has all of the input code and camera and all that, I create an empty Node3D called "controller" that takes that input. It has all of the controllable objects as children, and uses a variable called current_pawn to track which object is being controlled. The controller's script has two different functions for detecting input, and calls the correct one based on whether the current_pawn is a character or a vehicle.