Godot Version
v4.6.1.stable.fedora [14d19694e]
Question
Hey, i am trying to make shooting stuff in my game, one problem i am facing is how can i get a direction which is towards the center of the screen where my crosshair is. Bullets travel far and are fast so using Ray cast didn’t help. i am a beginner
Here is input script part when i press shoot
if Input.is_action_pressed("shoot") and shoot:
shoot = false
var b = bullet.instantiate()
get_tree().current_scene.add_child(b)
b.global_position = nozzle.global_position
# b.direction = what to write here????
await get_tree().create_timer(Global.BULLET_TIMEOUT).timeout
shoot = true
and here is bullet script
extends Area3D
@export var direction : Vector3
var speed = Global.BULLET_SPEED
func _physics_process(delta: float) → void:
if not direction : return
global_position += direction * speed * delta
func _on_timer_timeout() → void:
queue_free()
func _on_body_entered(body: Node3D) → void:
body.queue_free()
print(“Target Eliminated”)
queue_free()