Godot Version
v4.2.1.stable.official [b09f793f5]
Question
Hello !
I’m trying to understand why my newly created arrow/bullet follows my Mouse instead of the direction I gave in the beginning.
I have a shootingPoint that allways “look_at” my mouse position.
From this position I create an arrow that gets the position and rotation from my shootingPoint.
When I dont move my mouse while the arrow flies it all looks good, but if I move my mouse the direction of the arrow changes. That is not what I want.
Here is my Code:
Bow Script:
extends Area2D
func _ready():
pass
func _physics_process(_delta):
look_at(get_global_mouse_position())
func shoot():
const ARROW = preload("res://Projectiles/arrow.tscn")
var new_arrow = ARROW.instantiate()
%ShootingPoint.add_child(new_arrow)
new_arrow.global_position = %ShootingPoint.global_position
new_arrow.global_rotation = %ShootingPoint.global_rotation
new_arrow.rotate(deg_to_rad(90))
func _on_player_pressed_shoot():
shoot()
Arrow Script:
extends Area2D
var travelled_distance = 0
const SPEED = 200
const RANGE = 200
func _physics_process(delta):
var direction = Vector2.RIGHT.rotated(rotation)
position += direction * SPEED * delta
travelled_distance += SPEED * delta
if travelled_distance > RANGE:
queue_free()