Godot Version
4.3
Question
Everything seems to spawn in the top left before moving to the position I want to spawn it in. Let’s take projectiles as an example.
Simplified code below. We call _cast_throwable
, which in turn calls _create_projectile
, and then hits the Factory to create the relevant Projectile class and add it to the tree.
# combat_active.gd
## create ProjectileThrowable and activate
func _cast_throwable() -> void:
if _cast_position is Marker2D:
var projectile: ProjectileThrowable = _create_projectile(
_cast_position.global_position,
_effect_chain.on_hit
)
projectile.set_target_actor(target_actor)
projectile.activate()
_restart_cooldown()
else:
push_error("CombatActive: `_cast_position` not defined.")
## foundational method for creation of a projectile, used by calling specific `cast_*` method, e.g. `_cast_throwable`.
func _create_projectile(cast_position: Vector2, on_hit_callable: Callable) -> ABCProjectile:
var projectile: ABCProjectile = Factory.create_projectile(
_projectile_name,
_allegiance.team,
cast_position,
on_hit_callable
)
return projectile
# factory.gd
## create a projectile based on data in the library, then run setup when that projectile is ready.
func create_projectile(
projectile_name: String,
team: Constants.TEAM,
spawn_pos: Vector2,
on_hit_callable: Variant = null
) -> ABCProjectile:
# get base info
var dict_data: Dictionary = Library.get_projectile_data(projectile_name)
var data_class: DataProjectile = DataProjectile.new()
data_class.define([...])
# get specific subclass
var projectile: ABCProjectile
match dict_data["effect_delivery_method"]:
Constants.EFFECT_DELIVERY_METHOD.throwable:
# finish setting up data class
data_class.define_throwable([...])
projectile = _PROJECTILE_THROWABLE.instantiate() as ProjectileThrowable
if on_hit_callable != null:
projectile.hit_valid_target.connect(on_hit_callable)
# create and setup instance
projectile.ready.connect(projectile.setup.bind(spawn_pos, data_class), CONNECT_ONE_SHOT)
get_tree().get_root().add_child(projectile)
return projectile
The problem appeared in this commit, and was not apparent in the previous commit. I’ve reviewed the diffs and I can’t see anything that would cause this issue! It’s the same overall approach and most of the same code.
Example:
Any help would be greatly appreciated!
Snayff