Created
July 21, 2024 20:50
-
-
Save bramreth/91c86dbc981fbb45735992ba2bb07170 to your computer and use it in GitHub Desktop.
Source code for my RayCast3D Godot 4.2.2 Projectiles tutorial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends RayCast3D | |
@export var speed := 50.0 | |
@onready var remote_transform = RemoteTransform3D.new() | |
func _physics_process(delta: float) -> void: | |
position += global_basis * Vector3.FORWARD * delta * speed | |
target_position = Vector3.FORWARD * delta * speed | |
force_raycast_update() | |
var collider = get_collider() | |
if is_colliding(): | |
global_position = get_collision_point() | |
set_physics_process(false) | |
collider.add_child(remote_transform) | |
remote_transform.global_transform = global_transform | |
remote_transform.global_position = global_position | |
remote_transform.remote_path = remote_transform.get_path_to(self) | |
remote_transform.tree_exited.connect(cleanup) | |
func cleanup() -> void: | |
queue_free() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node3D | |
const PROJECTILE = preload("res://Projectile/projectile.tscn") | |
@onready var timer: Timer = $Timer | |
func _physics_process(delta: float) -> void: | |
if timer.is_stopped(): | |
if Input.is_action_pressed("click"): | |
timer.start() | |
var attack = PROJECTILE.instantiate() as RayCast3D | |
add_child(attack) | |
attack.global_transform = global_transform |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment