RemoteTransform2D not working as intended

Godot Version

4.5.1.stable

Question

hi, i’m trying to create a buckshot like projectile where, after some time has passed, it will break into smaller pieces and scatter, to do this i’m using a remote transform to place the projectiles at the edge of the bigger one, then i deactivate the collisions and physics processes until the bigger projectile is destroyed.

once that happens i wanted the smaller projectiles to activate their collisions and start moving forward

sceneTree:


result:

(small rhomboids on top are the smaller projectiles i want to shoot once the big one below dissapears)

however, for some reason once the projectile is shot the smaller ones appear somewhere else entirely


(that is where the (0,0) coordinates are for the main world scene)

i’ve set up the remote_path in the remoteTransform correctly so i don’t understand what the problem might be, is it with the transform of the remoteTransform itself?

i’ll leave the code for the projectiles here if needed

big one:

extends Projectile

@onready var time_to_shatter: Timer = $TimeToShatter
@onready var shards: Node = $Shards
@onready var sprite_2d: Sprite2D = $Sprite2D
@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D

func createProjectile() -> void:
	damage = baseDamage + (potency/3.5)
	rotate(atan2(direction.y,direction.x) + PI/2)
	for shard: Projectile in shards.get_children():
		shard.damage = damage/6

func projectileMovementLogic(delta: float) -> void:
	if not time_to_shatter.is_stopped():
		velocity = lerp(velocity,direction * speed,exp(-0.8 * delta))

func collidedWithEntity(_entityReference: Entity) -> void:
	if not time_to_shatter.is_stopped():
		queue_free()

func _on_time_to_shatter_timeout() -> void:
	if not is_queued_for_deletion():
		sprite_2d.hide()
		collision_shape_2d.set_deferred("disabled",true)
		for shard: Projectile in shards.get_children():
			shard.spawnShard()

func _on_time_to_die_timeout() -> void:
	if not is_queued_for_deletion():
		queue_free()

small one:

extends Projectile

@onready var collision_shape_2d: CollisionShape2D = $CollisionShape2D

func createProjectile() -> void:
	set_physics_process(false)
	await get_tree().physics_frame

func projectileMovementLogic(delta: float) -> void:
	velocity = lerp(velocity,direction * speed,exp(-0.8 * delta))

func collidedWithEntity(_entityReference: Entity) -> void:
	queue_free()

func spawnShard() -> void:
	set_physics_process(true)
	collision_shape_2d.set_deferred("disabled",false)
	visible = true

Make ShardLocations Node2D instead of Node

nothing changes

Do this for all plain nodes that have Node2D children. Inserting a plain Node in the midst of a Node2D hierarchy chain will break the transform inheritance for children nodes.

1 Like

had to change both the shard and shardPosition to node2D but now it works correctly :+1:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.