potassium-shot / godot-untrue

Some game structure nodes that are a little inspired by Unreal (but not too much), hence the name.
MIT License
5 stars 0 forks source link

Question: Character changing #2

Closed swapmasterx closed 9 months ago

swapmasterx commented 9 months ago

How would one go about implementing a character change system (like Team Fortress 2's class change system) with tying into Untrue's systems?

potassium-shot commented 9 months ago

If you want to swap the character during gameplay, you just have to change the player_character_scene of the GameMode to the PakcedScene of the new character, and the new player will automatically be instantiated. (You can get the current GameMode with Game.get_gamemode()

Do keep in mind the new character will be instantiated at a spawn point - if you want to keep its position, you can store its original position before the swap, and apply it again after the swap.

swapmasterx commented 9 months ago

Any potential issues with multiplayer implementations? Since it has to change the player character scene in the level. Also do I just put the character scene I want to change to in get_player_characters parentheses or is there more syntax?

potassium-shot commented 9 months ago

To be honest, I didn't use much of Godot's multiplayer yet and don't know exactly how it would interact with untrue. If the spawning and freeing of the character nodes is automatically replicated then there shouldn't be any issues.

And for your second question, the get_player_character function gets the current player character node, what you want to do instead is set the player_character_scene variable to your scene.

swapmasterx commented 9 months ago

Having trouble figuring out how to apply the stored player pos for the spectator body. My current code looks like this. It's called from when my hp manager hits 0 and calls this global function but not before grabing the player position and passing it into the die function.

const SPECTATOR = preload("res://character and weapons/classes/Spectator(death_state)/spectator.tscn")

func die(get_player_pos): Game.get_gamemode().player_character_scene = SPECTATOR

potassium-shot commented 9 months ago

In this code you would do

const SPECTATOR = preload("res://character and weapons/classes/Spectator(death_state)/spectator.tscn")

func die(get_player_pos):
    Game.get_gamemode().player_character_scene = SPECTATOR

    # get_player_character() now returns the new spectator instance
    Game.get_gamemode().get_player_character().global_position = get_player_pos
swapmasterx commented 9 months ago

Thank you. You and this plugin are loads of help. Keep up the good work