Hi, I don't know if someone can answer me that without seeing the whole Project but I'm following a tutorial right now, my goal was that a character has a staff, that automatically points at the first entity that got into an Area I have set up with "CollisionShape2D", now the pointing on the enemies with the Staff works fine but my problem is that the bullets always shoot 90° wrong, someone knows maybe why? I tried to find a solution but I don't see my mistake.
(As you can see in the picture the staff is directly pointing at the slimes but the projectile is flying 90° wrong)
Also here is a Video if that helps any further understanding the problem, where I show the problem and some of the things (If that is any useful):
https://www.youtube.com/watch?v=6Twkr9UnVoA
These are the scripts:
For the Staff
extends Area2D
func _physics_process(delta):
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://projectile_fireball.tscn")
var new_bullet = BULLET.instantiate()
new_bullet.global_position = %ShootingPoint.global_position
new_bullet.global_rotation = %ShootingPoint.global_rotation
%ShootingPoint.add_child(new_bullet)
func _on_timer_timeout():
%AnimationPlayer.play("Attack")
shoot()
For the Projectile "Fireball"
extends Area2D
var travelled_distance = 0
func _physics_process(delta):
%AnimationPlayer.play("default")
const SPEED = 500
const RANGE = 750
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):
queue_free()
if body.has_method("take_damage"):
body.take_damage()
I also added a picture of the Staff, I did 2 Marker2D's, one for the rotation of the whole staff around the character and one for the Shooting Point. And also added a pic of the scene for the projectile if necessary.
I would appreciate any help! Im kinda lost here.