Animate Arrow Particles left behind as it travel to enemy

Godot Version

4.4.1 Stable Mac OS

Question

` Script used for bullet(arrow)

extends Area2D


var travelled_distance = 0


func _physics_process(delta: float) -> void:
	const SPEED = 1000
	var RANGE = 1200
	var direction = Vector2.RIGHT.rotated(rotation)
	position += direction * SPEED * delta
	travelled_distance += SPEED *delta
	
	if travelled_distance > RANGE :
		queue_free()
		
		


func _on_body_entered(body: Node2D) -> void:
	queue_free()
	if body.has_method("take_damage"):
		body.take_damage()

Script used for “weapon” - invisible pivot point to launch arrow


extends Area2D

@onready var AmmoLabel: Label = get_node("/root/TestLevel/UI/UIContainer/Ammo")
func _physics_process(delta: float) -> void:
	var enemies_in_range = get_overlapping_bodies()
	if enemies_in_range.size() > 0:
		var target_enemy = enemies_in_range.front()
		look_at(target_enemy.global_position)

func shoot():
	const BULLET = preload("res://Geometry/Bullets/bullet.tscn")
	
	# Only shoot if ammo > 0
	if AmmoLabel.ammo_amount > 0:
		var enemies_in_range = get_overlapping_bodies()
		if enemies_in_range.size() > 0:
			var new_bullet = BULLET.instantiate()
			new_bullet.global_position = %ShootingPivot.global_position
			new_bullet.global_rotation = %ShootingPivot.global_rotation
			%ShootingPivot.get_parent().add_child(new_bullet)
			
			# Reduce ammo after shooting
			AmmoLabel.ammo_shoot(1)

func _on_timer_timeout() -> void:
	shoot()


Bullet is sprite2D with Child GPUParticles2D - Sprite is rotated 90 degrees as picture pointing up instead of right , GPUParticles I have used Spawn-Angle min - 90 degree , max -90 degree to basically align with sprite but this unfortunately doesn’t adapt if its shot with different angle then right .


Video demonstration of what is going on -

`

I’m keep trying things like

particles.angle_min = particles.angle_max
new_bullet.global_position = %ShootingPivot.global_rotation
particles.angle_max = %ShootingPivot.global_rotation


but thing is bullet won’t exist in scene till it shot so how can I refer to it to modify angle to match angle of pivot and new bullet ?

Here is demonstration with manual adjustment of Sprite and GPUParticles

If transformation - rotation of sprite is 90 degrees - arrow points right of screen, to match it in particles Process Material -Spawn - Angle need to be set -90 degrees

if transformation - rotation of sprite if 0 / 360 degree - arrow points up of screen, to match it in particles Process Material -Spawn - Angle need to set 0/360 ( this match with negative or positive )

same goes for down as for up

for left goes same as for right need to create negative value of degrees to match direction of sprite , or create double of value so 240 positive for example match 120 degrees of positive on particle angle :slight_smile:

Any ideas how to create shooting arrow with particle system leaving traces behind matching rotation from pivot point which determine position of enemy ?

Rotation and position is already done in shooting code which is attached to this pivot point for shooting a new_bullets

Could you assign the particle rotation under _ready?

func _ready() -> void:
    var particle: ParticleProcessMaterial = $Bullet/GPUParticles2D.process_material
    particle.angle_min = -rotation
    particle.angle_max = -rotation
1 Like

Not sure , the thing is with this preloading and on_ready how to refer to bullet which is basically scene but it make parent.childnode once shot .

I mean _ready on the bullet script.

1 Like

Hmm , this could works only wonder about rotation as this is determined by ShootingPoint which exist in Weapon node

The value will be applied in time since _ready is called when you use add_child, so in this sample the rotation is applied before add_child, it will be correct.

1 Like

I’m not sure I follow why the individual components here need rotation; if they’re child nodes of a parent node, changing the parent node’s rotation here should suffice. Here’s a node tree from a game where arrows have trails:

The parent Arrow node is moved along its forward direction when necessary and its rotation is configured to point its forward direction just once:

So perhaps here, the particles need changing to better match the parent sprite? It looks like this:

1 Like

This looks nice .
Can you try rotate or make curve( behave like arrow going up and down after distance ) this way ?

As long as the parent object is rotated correctly and the forward direction makes sense, I’m fairly sure this will work.

1 Like

So I have tried it here is final effect of it , I have tried also refer to Bullet(Sprite) and use it with global_rotation but it end up with exactly same effect as -rotation , when WeaponPivot change rotation it effects particles

Well this is where is issue , as I get lost within rotation as using using two Pivots , one for change position of “weapon” and another for offset of “weapon” from player and at same time is position where arrow is instantiated .

Remote Scene Tree during two arrows launched -

Keychange was change sprite to avoid rotate in transform for sprite and particle system made 90 degrees difference , originally sprite for both arrow and particle pointed up but direction for launching is Vector2.Right so this made it more confusing for launching and orientation topped by fact PivotPoint .

It not looks smooth as @sp_yjase your demonstration but I found flaw , ideally in particle system would have transformation which affects Texture size and Rotation
Also Size of Texture it can be only changed through Process_Material → Display → Scale

Current look of it is quite funny @sp_yjase @gertkeno


notice how this change rotation for all particles not only those within child

Final code which solved this , it make unique copy which keep track till queue_free

func _ready() -> void:
	var particle: GPUParticles2D = $GPUParticles2D
	particle.process_material = particle.process_material.duplicate(true)
	var mat := particle.process_material as ParticleProcessMaterial
	if mat:
		mat.angle_min = -rotation_degrees
		mat.angle_max = -rotation_degrees

@sp_yjase @gertkeno - thank you for suggestions

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