- Edited
Jesusemora thank you for replying and getting to help me solve another issue man, but, i don't know if i did something wrong, probably did, but it didn't do much really, maybe it was more accurate, but i cant really put my finger there. Before i put the code, just wanna clarify some things that i may have left out the picture.
The first is my answer if it's an arcade or simulation, and i guess it's really inclined for an arcade, so i don't actually expect something really accurate to reality. The second is that all of this is done on the script of the bullet, maybe i should do it somewhere else? Third is that, even if it actually destroys the bullet, my main problem is that a bullet travels really far and really quick, so the speed should be high, but if the speed is high, the chances of destroying on collision is really low because it just phases everything.
extends Node3D
const SPEED = 100.0
var tim : float = 0.0
var lifetime : float = 10.0
@onready var mesh = $MeshInstance3D
@onready var ray = $RayCast3D
func _process(delta):
position += transform.basis * Vector3(0,0, -SPEED) * delta
func _ready():
pass # Replace with function body.
func _physics_process(delta):
#projectile self destructs after lifetime ends
if tim < lifetime:
tim += delta
else:
selfDestruct()
#projectile hits something
if ray.is_colliding():
print ("ray is colliding")
get_tree().create_timer(0.0).timeout
selfDestruct()
else:
ray.translate_object_local(ray.target_position * delta) #move the projectile
func _on_timer_timeout():
queue_free()
func selfDestruct():
queue_free()