Scripts renamed
This commit is contained in:
parent
484fb75fa3
commit
aa35ee5975
17 changed files with 7 additions and 5 deletions
21
scripts/player/crosshair.gd
Normal file
21
scripts/player/crosshair.gd
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
extends Control
|
||||
|
||||
|
||||
@export var outline: bool = true
|
||||
@export var outline_color: Color = Color.BLACK
|
||||
@export var outline_width: float = 0.1
|
||||
|
||||
@export var dot_radius: float = 1.0
|
||||
@export var dot_color: Color = Color.WHITE
|
||||
|
||||
@export var crosses_width: float = 1.0
|
||||
@export var crosses_length: float = 2.0
|
||||
@export var crosses_offset: float = 0.2
|
||||
@export var crosses_color: Color = Color.WHITE
|
||||
|
||||
func _draw() -> void:
|
||||
draw_circle(Vector2(0,0),dot_radius,dot_color,true,outline_width)
|
||||
for i in range(0,4):
|
||||
var direction: Vector2 = Vector2.RIGHT.rotated(i*PI/2)
|
||||
var offset_position: Vector2 = direction * crosses_offset
|
||||
draw_line(offset_position,direction*crosses_length+offset_position,crosses_color,crosses_width)
|
||||
1
scripts/player/crosshair.gd.uid
Normal file
1
scripts/player/crosshair.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dalwlndejfdhm
|
||||
64
scripts/player/player.gd
Normal file
64
scripts/player/player.gd
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
@export var animation_player: AnimationPlayer
|
||||
@export var stand_up_area: Area3D
|
||||
|
||||
@export var CROUCH_TIME: float = 1.0
|
||||
@export var SPEED: float = 5.0
|
||||
@export var JUMP_VELOCITY: float = 4.5
|
||||
# Replace with settings
|
||||
@export var TOGGLE_CROUCH: bool = true
|
||||
@export var WALK_MODIFIER: float = 0.5
|
||||
|
||||
var crouched: bool = false:
|
||||
set(value):
|
||||
if value != crouched and stand_up_area.has_overlapping_bodies() == false:
|
||||
crouched = value
|
||||
update_crouch()
|
||||
SPEED = (SPEED*WALK_MODIFIER) if crouched else (SPEED/WALK_MODIFIER)
|
||||
potential_crouched = value
|
||||
get:
|
||||
return crouched
|
||||
|
||||
var potential_crouched: bool = crouched
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if potential_crouched != crouched:
|
||||
crouched = potential_crouched
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("plr_jump") 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("plr_strafe_l", "plr_strafe_r", "plr_forward", "plr_back")
|
||||
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
if direction:
|
||||
velocity.x = direction.x * SPEED
|
||||
velocity.z = direction.z * SPEED
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
velocity.z = move_toward(velocity.z, 0, SPEED)
|
||||
|
||||
move_and_slide()
|
||||
|
||||
func update_crouch():
|
||||
if crouched:
|
||||
animation_player.play("Crouch",-1,1/CROUCH_TIME)
|
||||
else:
|
||||
animation_player.play("Crouch",-1,-1/CROUCH_TIME,true)
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("plr_crouch"):
|
||||
if TOGGLE_CROUCH:
|
||||
crouched = not crouched
|
||||
else:
|
||||
crouched = true
|
||||
elif event.is_action_released("plr_crouch") and TOGGLE_CROUCH == false:
|
||||
crouched = false
|
||||
1
scripts/player/player.gd.uid
Normal file
1
scripts/player/player.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://3dphlay25fih
|
||||
16
scripts/player/player_camera.gd
Normal file
16
scripts/player/player_camera.gd
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
extends Camera3D
|
||||
|
||||
const COLLINEAR = 1.5707963267948966
|
||||
|
||||
@export var SENSITIVITY = 0.02
|
||||
|
||||
func _ready() -> void:
|
||||
# Move to level controller when possible
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseMotion:
|
||||
get_parent().rotate_y(-event.relative.x * SENSITIVITY)
|
||||
rotate_x(-event.relative.y * SENSITIVITY)
|
||||
rotation.x = clamp(rotation.x,-COLLINEAR,COLLINEAR)
|
||||
orthonormalize()
|
||||
1
scripts/player/player_camera.gd.uid
Normal file
1
scripts/player/player_camera.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bjhbdh6xsjgnn
|
||||
4
scripts/player/player_global.gd
Normal file
4
scripts/player/player_global.gd
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
extends Node
|
||||
|
||||
|
||||
var player: CharacterBody3D
|
||||
1
scripts/player/player_global.gd.uid
Normal file
1
scripts/player/player_global.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dv3pm11t6p4si
|
||||
Loading…
Add table
Add a link
Reference in a new issue