Skip to content

Instantly share code, notes, and snippets.

@lamarmarshall
Created March 1, 2025 19:44
Show Gist options
  • Save lamarmarshall/1eeeb3b60f21e14514914b0a4e153481 to your computer and use it in GitHub Desktop.
Save lamarmarshall/1eeeb3b60f21e14514914b0a4e153481 to your computer and use it in GitHub Desktop.
godot 4, aim, shoot
extends Node3D
@export var projectile: PackedScene
@onready var turret_top: MeshInstance3D = $TurretBase/TurretTop
var enemy_path: Path3D
func _physics_process(delta: float) -> void:
var enemy = enemy_path.get_children().back()
look_at(enemy.global_position, Vector3.UP, true)
func shoot(start_position: Vector3) -> void:
var shot = projectile.instantiate()
add_child(shot)
shot.global_position = start_position
shot.direction = basis.z
func _on_timer_timeout() -> void:
shoot(turret_top.global_position)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment