xyz alright but its the whole player script. the raycast bit is about a third of the way down
extends CharacterBody3D
class_name player
#variables and shit
@onready var headboy = $headboy
@onready var bigboycollider = $bigboycollider
@onready var smallboycollider = $smallboycollider
@onready var ray_cast_3d = $RayCast3D
@onready var interact_ray = $headboy/interact_ray
var lerp_speed = 10
var current_speed = 0
var mouse_sens = 0.2
var direction = Vector3.ZERO
var crouch_depth = -0.5
var lightup = false
var paused = false
#constants
const WALK_SPEED = 4.5
const JUMP_VELOCITY = 6
const SPRINT_SPEED = 8
const CROUCH_SPEED = 2.5
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
#mouse input
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
$headboy/Camera/flashliught.light_energy = 0
$"../pausebutt".visible = false
$"../pausebg".visible = false
func _input(event):
if event is InputEventMouseMotion and paused == false:
rotate_y(deg_to_rad(-event.relative.x * mouse_sens))
headboy.rotate_x(deg_to_rad(-event.relative.y * mouse_sens))
headboy.rotation.x = clamp(headboy.rotation.x,deg_to_rad(-89), deg_to_rad(89))
#checks for schtuff
func _physics_process(delta):
if interact_ray.is_colliding():
var collision = interact_ray.get_collider()
if collision.is_in_group("collectible"):
print("collectible")
if Input.is_action_pressed("crouch"):
current_speed = CROUCH_SPEED
headboy.position.y = lerp(headboy.position.y,0.519 + crouch_depth, delta*lerp_speed)
bigboycollider.disabled = true
smallboycollider.disabled = false
elif !ray_cast_3d.is_colliding():
bigboycollider.disabled = false
smallboycollider.disabled = true
headboy.position.y = lerp(headboy.position.y,0.519, delta*lerp_speed)
if Input.is_action_pressed("sprint"):
current_speed = SPRINT_SPEED
else:
current_speed = WALK_SPEED
#flashlight toggle shits
if Input.is_action_just_pressed("flashlight") and lightup == false:
$headboy/Camera/flashliught.light_energy = 0.835
$headboy/Camera/flashliught/clickon.play()
lightup = true
print("on")
elif Input.is_action_just_pressed("flashlight") and lightup == true:
$headboy/Camera/flashliught.light_energy = 0
$headboy/Camera/flashliught/clickoff.play()
lightup = false
print("off")
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
#pause toggle shits
if Input.is_action_just_pressed("escape") and paused == false:
$"../pausebutt".visible = true
$"../pausebg".visible = true
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
paused = true
print("pause")
elif Input.is_action_just_pressed("escape") and paused == true:
$"../pausebutt".visible = false
$"../pausebg".visible = false
paused = false
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
print("unpause")
# Handle jump.
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
print("jumpy guy")
# 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", "backward")
direction = lerp(direction, (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized(),delta*lerp_speed)
if direction:
velocity.x = direction.x * current_speed
velocity.z = direction.z * current_speed
else:
velocity.x = move_toward(velocity.x, 0, current_speed)
velocity.z = move_toward(velocity.z, 0, current_speed)
move_and_slide()
func _on_back_pressed():
$"../click".play()
FadeTransition.change_scene_to_file("res://menu2/mainmenu2.tscn")