- Edited
Hello!
I want some lights to change their power (or just hide them if it's to hard to code it) after player go to a trigger zone. I can't make even a triggered printf to console
It is a simple scene, after making 3D FPS controller, I just added nodes represented by hierarchy you see on the screenshot, and I try to
write code to it with different tutorials, but something is not working...
I am using Godot 4.0.1.
<code below images>
AreaLightSwitchAfterPlayerInto.gd
extends Area3D
func _ready() -> void:
print("I'm in _ready area2")
func _process(delta: float) -> void:
pass
func _on_Area3D_body_entered(body) -> void:
print("I'm in Area3D")
func _on_Area3D_body_exited(body) -> void:
print("I'm out of Area3D")
Player.gd
extends CharacterBody3D
@export_group("MOVEMENT PARAMETERS")
@export var speed : float = 2.0
@onready var HeadbobAnimation : AnimationPlayer = $AnimationPlayer
const JUMP_VELOCITY = 4.5
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@onready var neck := $Neck
#@onready $Neck
@onready var head := $Neck/Head
func _unhandled_input(event: InputEvent):
if event is InputEventMouseButton:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) #nie widzimy kursora!
elif event.is_action_pressed("ui_cancel"): #gdy ESC!
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) #Gdy ESC widzimy kursor!
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
if event is InputEventMouseMotion:
neck.rotate_y(-event.relative.x * 0.003)
head.rotate_x(-event.relative.y * 0.003)
head.rotation.x = clamp(head.rotation.x, deg_to_rad(-15), deg_to_rad(30))
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
# Handle Jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("left", "right", "forward", "back")
var direction = (neck.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
#velocity.x = direction.x * SPEED
velocity.z = direction.z * speed #chodzenie na boki
velocity.x = direction.x * speed
else:
velocity.x = move_toward(velocity.x, 0, speed)
velocity.z = move_toward(velocity.z, 0, speed)
if direction != Vector3(): HeadbobAnimation.play("HeadbobAnimation")
else: HeadbobAnimation.play("IdleAnimation")
move_and_slide()
func _on_area_3d_area_entered(area: Area3D) -> void:
print("I'm in Area3D")
pass # Replace with function body.
func _on_area_3d_area_exited(area: Area3D) -> void:
print("I'm out of Area3D")
pass # Replace with function body.