Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody
- var view_angle: float = 0.0
- var sensitivity: float = 0.2
- const GRAVITY: float = -9.8 * 2.6
- const MAX_SPEED: float = 16.0
- const MAX_RUNNING_SPEED: float = 22.0
- var can_freeze: bool = false
- var accel: float = 5.4
- var deaccel: float = 1
- var speed: float = 8.0
- var jump_height: float = 8
- var movement = Vector3(0, 0, 0)
- var looking = Vector3(0, 0, 0)
- # Coyote Timers
- # [ Current Time, Starting Value, Optional Values ]
- var coyote_landing = [0.0, 0.4]
- var coyote_cliff = [0.0, 0.65]
- var wacky_time = [0.0, 0.33]
- func jir(action: String) -> bool:
- return Input.is_action_just_released(action)
- func jiv(action: String) -> bool:
- return Input.is_action_just_pressed(action)
- func civ(action: String) -> bool:
- return Input.is_action_pressed(action)
- func _ready() -> void:
- Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
- Input.set_custom_mouse_cursor(load("res://static/cursor.png"), 0)
- func _process(delta: float) -> void:
- if jiv("exit"):
- get_tree().quit()
- elif jiv("restart"):
- get_tree().reload_current_scene()
- looking = Vector3(0, 0, 0)
- var perspective = $Head/Camera.get_camera_transform().basis
- if civ("forward"): looking -= perspective.z
- if civ("backward"): looking += perspective.z
- if civ("right"): looking += perspective.x
- if civ("left"): looking -= perspective.x
- looking = looking.normalized()
- if civ("timefreeze") and can_freeze:
- wacky_time[0] -= delta
- if wacky_time[0] < 0:
- wacky_time[0] = 0
- can_freeze = false
- Engine.time_scale = 1
- else:
- Engine.time_scale = 0.2
- elif not civ("timefreeze"):
- wacky_time[0] += 0.02
- if wacky_time[0] > wacky_time[1]:
- wacky_time[0] = wacky_time[1]
- can_freeze = true
- Engine.time_scale = 1
- coyote_cliff[0] -= delta
- if is_on_floor():
- coyote_cliff[0] = coyote_cliff[1]
- coyote_landing[0] -= delta
- if jiv("jump"):
- coyote_landing[0] = coyote_landing[1]
- if coyote_landing[0] > 0 and coyote_cliff[0] > 0:
- coyote_landing[0] = 0
- coyote_cliff[0] = 0
- movement.y = jump_height
- if not is_on_floor(): movement.y += GRAVITY * delta
- var current_speed: float
- if civ("sprint"):
- current_speed = MAX_RUNNING_SPEED
- else:
- current_speed = MAX_SPEED
- var true_movement = movement
- true_movement.y = 0
- if jiv("turn"):
- $Head.rotate_y(deg2rad(180))
- var current_acceleration
- if looking.dot(true_movement) > 0:
- current_acceleration = accel
- else:
- current_acceleration = deaccel
- var target: Vector3 = looking * speed
- true_movement = movement.linear_interpolate(target, accel*delta)
- movement.x = true_movement.x
- movement.z = true_movement.z
- movement = move_and_slide(movement, Vector3.UP)
- func _input(event: InputEvent) -> void:
- if event is InputEventMouseMotion:
- var horizontal = -event.relative.x * sensitivity
- var vertical = -event.relative.y * sensitivity
- $Head.rotate_y(deg2rad(horizontal))
- if vertical + view_angle < 90 and vertical + view_angle > -90:
- view_angle += vertical
- $Head/Camera.rotate_x(deg2rad(vertical))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement