I’m creating a very interesting horror game about a boy who survives in a kindergarten and escapes from creepy toys. Some of them act as staff, replacing humans, while others are ordinary toys.
When I launch the map, the first item I need to get, the flashlight, just doesn’t work. I’ve written scripts based on the tutorials, trying to make sure the flashlight can be picked up, but when I try, there’s no indication of the click button, and the object itself can’t be picked up.
extends SpotLight3D
var picked_up = false
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if Input.is_action_just_pressed("flashlight") && picked_up == true:
visible = !visible
$toggie.play()
extends RayCast3D
var int_text
func _ready():
int_text = get_node("/root/" + get_tree().current_scene.name + "/UI/interact_text")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if is_colliding():
var hit = get_collider()
if hit.has_method("interact"):
int_text.visible = true
if Input.is_action_just_pressed("interact"):
hit.interact()
else:
int_text.visible = false
else:
int_text.visible = false
This is a raycast
If you see that I made any mistakes or you need more screenshots, I can send them to you from below. This is very important to me because otherwise I can’t continue with the next stages of the video tutorials.
When I extended the ray beam, I realized that perhaps it wasn’t the ray beam that was responsible, but the object itself, which for some reason didn’t obey it.
There is no print, or it should be invisible. In any case, the action button designation did not appear on top, as well as the object itself is not selected.
Forget about the object for now. You first need to determine if the raycast itself is colliding. Put a print statement in that block as I suggested and look into the engine’s output window if it prints that phrase when the camera is near and aimed at area.
Just in the output window, if I hope I understood correctly, I noticed that it says “Raycast is colliding”, Apparently this is an infinite number of times when I came and left the object, or maybe something else
This meant that the reaycast itself is colliding properly. Your code that reacts to that collision may have bugs though.
First, get_collider() will return the Area3D node the the ray hit. If a script that has the interact() method is not attached to that node, nothing will happen because your script expect that. So you likely need to get the parent of that are node, if that’s where interact() is.
I’m a newcomer in godot 3D myself, and Butterfly Kindengarten is actually my very first game that I make, which is why I can sometimes make mistakes in the code, although I try to find solutions to fix them.
The most suitable part of the flashlight looks like this long cylindrical part. Since it is suitable for the raycast beam, however, if the flashlight is in an inverted position facing the player, it will be more difficult to determine the end of the raycast beam, so it may be better to choose the top of the flashlight.