Reputation: 1
I've been following this Godot tutorial on YouTube https://www.youtube.com/watch?v=GwCiGixlqiU , but I'm having issues with the gun shooting in the wrong direction. I believe I've done everything correctly, but I'm still encountering problems. Can anyone help me figure out if I made a mistake or if this is an issue with Godot?
# Bullet script
extends Area2D
const SPEED = 1000
const RANGE = 1200
var travelled_distance = 0
var direction = Vector2.RIGHT.rotated(rotation)
func _physics_process(delta):
var movement = direction * SPEED * delta
position += movement
travelled_distance += movement.length()
if travelled_distance > RANGE:
queue_free()
func _on_body_entered(body):
queue_free()
if body.has_method("take_damage"):
body.take_damage()
# Shooter script
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://scnes/bullet.tscn")
var new_bullet = BULLET.instantiate()
new_bullet.global_rotation = $Point.global_rotation
new_bullet.global_position = $Point.global_position
$Point.add_child(new_bullet)
func _on_timer_timeout():
shoot()
The bullet seems to be shooting in an unexpected direction.
I ensured that the direction is set correctly by rotating Vector2.RIGHT
with the bullet's rotation.
The shooting logic is supposed to instantiate a bullet at the correct position and rotation of the Point node.
What could be causing the bullet to shoot in the wrong direction?
Upvotes: 0
Views: 98