#The door function does not work correctly
6 messages · Page 1 of 1 (latest)
Players code:
extends CharacterBody3D
@onready var raycast = $RayCast3D
@onready var animation_player: AnimationPlayer = $AnimationPlayer
var target_velocity = Vector3.ZERO
var speed = 1
var rotation_speed = 90.0
var rotating = false
var moving = false
var current_rotation = 0.0
var target_rotation = 0.0
var distance_to_move = 1.0
var distance_moved = 0.0
var time_standing = 0.0
var is_running = false
var collision_detected = false
func _physics_process(delta):
var direction = Vector3.ZERO
var camera_forward = -get_global_transform().basis.z.normalized()
if Input.is_action_pressed("turn_left") and not rotating and not moving:
target_rotation = current_rotation + 90.0
rotating = true
if Input.is_action_pressed("turn_right") and not rotating and not moving:
target_rotation = current_rotation - 90.0
rotating = true
if rotating:
rotate_character(delta)
if Input.is_action_pressed("move_forward") and not rotating:
if not moving:
if not $RayCast3D.is_colliding() or $RayCast3D.get_collider().has_method("interact"):
distance_moved = 0.0
moving = true```
if moving:
direction = camera_forward
animation_player.play("Run")
distance_moved += speed * delta
if distance_moved >= distance_to_move:
is_running = true
moving = false
distance_moved = 0.0
time_standing = 0.0
else:
if is_running:
if $RayCast3D.is_colliding() and collision_detected:
moving = false
print(47)
is_running = false
collision_detected = false
time_standing += delta
if time_standing >= 0.2:
animation_player.play("stop_run")
is_running = false
collision_detected = false
else:
time_standing = 0.0
target_velocity = direction * speed
velocity = target_velocity
if moving and $RayCast3D.is_colliding() and not collision_detected:
animation_player.play("stop_run")
is_running = false
collision_detected = true
move_and_slide()
func rotate_character(delta):
var rotation_amount = rotation_speed * delta
if current_rotation < target_rotation:
rotate_y(deg_to_rad(rotation_amount))
current_rotation += rotation_amount
if current_rotation >= target_rotation:
current_rotation = target_rotation
rotating = false
elif current_rotation > target_rotation:
rotate_y(deg_to_rad(-rotation_amount))
current_rotation -= rotation_amount
if current_rotation <= target_rotation:
current_rotation = target_rotation
rotating = false
Method "interact" just fades the screen
RayCast3D code(maybe it needs):