Skip to content

Commit

Permalink
Add projectile scaling workaround
Browse files Browse the repository at this point in the history
Adds a workaround that manually scales the children of the Projectile
scene.
This is due to a problem where the projectile root node scale does not
propagate down to the sprite or collision shape within it.

godotengine/godot#5734
  • Loading branch information
Checkroth committed Aug 19, 2024
1 parent efcdffe commit c7ee0b5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion units/projectile.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ func spawn(owner: Node, spawn_with_projectile_effects: Array[ProjectileEffect],
projectile_effects = spawn_with_projectile_effects
var local_transform = parent_transform
for effect in projectile_effects:
add_child(effect.instantiate())
add_child(effect)
effect.set_owner(self)
effect.modify_creation(owner, projectile_effects, local_transform)
# Spawn the default projectile
# TODO:: Projectile spawn modification may want to prevent the default from spawning
Expand All @@ -19,8 +20,19 @@ func spawn(owner: Node, spawn_with_projectile_effects: Array[ProjectileEffect],
projectile_effects = projectile_effects
transform = local_transform

func scale_projectile(new_scale: Vector2):
$Sprite2D.scale = new_scale
$CollisionShape2D.scale = new_scale

func _ready():
if scale != Vector2.ONE:
scale_projectile(scale)

func _physics_process(delta):
var position_modifier = transform.x * SPEED * delta
for effect in projectile_effects:
position_modifier = effect.modify_physics(position_modifier)
set_position(position + position_modifier)

func _integrate_forces(delta):
scale = Vector2(100, 100)

0 comments on commit c7ee0b5

Please sign in to comment.