Godot Version
4.2.2 stable
Question
I’m creating a small top-down shooter game and I’m having trouble with a special attack. I’m adding a Sprite node to a Marker2D called ShootingPoint. The normal attack works as intended, but when I apply the same setup for the special attack, it fires in a different direction than expected. The rotation is just off. I would highly appreciate any help because I just can’t figure out what’s causing the problem.
book(weapon).gd
extends Area2D
const BULLET = preload("res://bullet.tscn")
const SPECIAL_ATTACK = preload("res://special_attack.tscn")
const FIRE_RATE = 0.2
var can_fire = true
func _physics_process(_delta):
var mouse_position = get_global_mouse_position()
look_at(mouse_position)
func _process(delta):
if Input.is_action_pressed("attack") and can_fire:
shoot()
can_fire = false
await get_tree().create_timer(FIRE_RATE).timeout
can_fire = true
func shoot():
if Global.score % 200 == 0:
shooting_particle(SPECIAL_ATTACK.instantiate())
else:
shooting_particle(BULLET.instantiate())
func shooting_particle(bullet_type):
bullet_type.global_position = %ShootingPoint.global_position
bullet_type.global_rotation = %ShootingPoint.global_rotation
%ShootingPoint.add_child(bullet_type)
special_attack.gd:
extends Area2D
var travelled_distance = 0
func _physics_process(delta):
const SPEED = 10000
const RANGE = 12000
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):
if body.has_method(“take_damage”):
body.take_damage(true)
Here is screenshot of the game: