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 .
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
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
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.
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:
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 .
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