I am so exhausted by this because I don’t understand in the slightest how any of this works, I can’t see any logic to this
It’s not the update because this has been an issue since a couple weeks back
I’ve been exhausted trying to figure out why this is happening but I have no clue
I’m trying to code an enemy that fires a projectile at the player, but for some reason Godot seems to think forward is down and down is up forward, back is down and up is down. (I’ve tested them all, DOWN works but the aim is horrendous as it fires up only)
Here is the code;
extends RayCast3D
@export var Speed : float = 50.0
var debug = 0
@onready var timer = $Timer
@onready var despawn = $Timer2
func _ready() -> void:
timer.timeout.connect(fire)
pass
func _physics_process(delta: float) -> void:
force_raycast_update()
func fire():
#$AudioStreamPlayer.play()
target_position += Vector3.FORWARD * Speed
position += target_position
#target_position = Vector3.FORWARD * Speed * delta
if is_colliding():
#print("Collision")
set_physics_process(false)
var collider = get_collider()
print(collider)
global_position = get_collision_point()
if collider == Autoload.player:
queue_free()
else:
cleanup()
func cleanup():
despawn.start()
await despawn.timeout
queue_free()
You haven’t communicate the full context clearly.
Why do you need a raycast for in this case? Is this player’s bullet that is fired down the player’s look direction or an enemy bullet fired at the player?
Why are you adding to target_position every time fire is called? Should this be an assignment instead? You probably do not have to update target_position in a script anyways, it is relative to the node’s position.
You also do not need to force raycast updates every physics frame.
Negative on the z-axis is forward. If I had to guess, I’d say you have your model oriented on the wrong axis. In which case you think down is forward, and that’s why you are seeing what you are seeing. There are a couple ways to fix this. One is to make sure that when you export your model from Blender, you tell it that -Z is forward. (It’s in the export dialog box.) If that’s not an option, you can either manually rotate the model’s facing after you import, or write an import script to do it.
Keep in mind that you cannot rotate the root node of an object, so when you import the model, if it’s hanging off a Node3D, rotate the MeshInstance3D node(s) underneath it, not the root Node3D.
I’ll also echo what @normalized and @gertkeno said, because those issues need to be fixed too.
A few other notes:
pass should be deleted from production code.
Best practice is to not capitalize variable names (Speed).
Not sure how long your despawnTimer is, but ti should not be necessary. You can just call queue_free().