最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

godot - How to sync nested properties with PlayerSyncronizer - Stack Overflow

programmeradmin3浏览0评论

I've found a problem in my code.

I have the class Character , which has a property called characterState that is an type of "CharacterState", inside my characterState I have the property "current_state" which is responsible to reflect my character state, my question is if there's any way to sync this data inside my class "Player" which inherits from "Character" and have a MultiplayerSyncronizer as a node.

Here is my example:

#Player class
extends BaseCharacter

class_name Player

var jump_force = -250
var speed = 200
var attack_damage = 300
var health = 1000

@export var player_id := 1:
   set(id):
       player_id = id
       %InputSyncronizer.set_multiplayer_authority(id)

@onready var player_syncronizer: MultiplayerSynchronizer = $PlayerSyncronizer


func _init():
   super(jump_force, speed, attack_damage, health)

# Character class
extends CharacterBody2D

class_name BaseCharacter

var state: CharacterState


func _init(jump_force, speed, attack_damage, health):
   self._jump_force = jump_force
   self._speed = speed
   self._attack_damage = attack_damage
   self._health = health

func _ready():
   state = CharacterState.new(self)
   add_child(state)

#CharacterState class
extends Node

class_name CharacterState

enum States { IDLE, RUNNING, JUMPING, ATTACKING, RECEIVING_DAMAGE, DEAD, PARRYING, DASHING }

var current_state = States.IDLE

var character: CharacterBody2D

signal character_state_change

func _init(character: CharacterBody2D):
   self.character = character
   self.name = "character_state"

func change_state(new_state):
   if _state_change_is_blocked:
       return
   if current_state == States.DEAD:
       return
   if new_state == States.RUNNING and current_state == States.RUNNING:
       return
   elif new_state == States.IDLE and current_state == States.IDLE:
       return
   elif new_state == States.JUMPING and current_state == States.JUMPING:
       return
   else:
       current_state = new_state
       self.character_state_change.emit(self.current_state)

I'm trying to sync this property here in my godot editor:

using the following path :character_state:current_state but I had no success doing this way...

Is there anyway to sync my properties nested or I can only do it in the same level of the node "MultiplayerSyncronizer" ?

发布评论

评论列表(0)

  1. 暂无评论