extends KinematicBody
classname Player
signal damaged(hp)
signal chargem(gems)
signal depth_count( depth )
BEGGINING
var gem = 0
var velocity = Vector3( 0 , 0 , 0 )
var y_velocity : float
export var health = 900
const SPEED = 6
export var jumpforce = 20
export var acceleration = 15
export var airacceleration = 5
export var gravity = 0.98
export var maxterminalvelocity = 54
export(float , 0.1 , 1) var mousesensitivity = 0.3
export(float , -90 ,0) var minpitch = -90
export(float , 0, 90) var max_pitch = 90
var camera_direction = Vector3()
onready var camera_pivot = $CamerPivot
func ready():
Input.setmousemode(Input.MOUSEMODE_CAPTURED)
func process(delta):
if Input.isactionjustpressed("uicancel") :
Input.setmousemode(Input.MOUSEMODEVISIBLE)
healthregeneration(delta)
func _input(event):
if event is InputEventMouseMotion :
rotation_degrees.y -= event.relative.x * mouse_sensitivity
camera_pivot.rotation_degrees.x -= event.relative.y *mouse_sensitivity
camera_pivot.rotation_degrees.x = clamp(camera_pivot.rotation_degrees.x , min_pitch , max_pitch)
func physicsprocess(delta):
#I CANT PUT THIS VAR IN THE BEGINNING /
var depth :int = global_transform.origin.y
handle_movement(delta)
emit_signal("damaged" , health)
emit_signal("char_gem" , gem)
emit_signal("depth_count", depth)
func handle_movement(delta):
var direction = Vector3()
if Input.is_action_pressed("forward"):
direction -= transform.basis.z
if Input.is_action_pressed("backward"):
direction += transform.basis.z
if Input.is_action_pressed("left"):
direction -= transform.basis.x
if Input.is_action_pressed("right"):
direction += transform.basis.x
direction = direction.normalized()
var accel = acceleration if is_on_floor() else air_acceleration
velocity = velocity.linear_interpolate(direction * SPEED , accel * delta)
if is_on_floor() :
y_velocity = - 0.01
else :
y_velocity = clamp(y_velocity - gravity , -max_terminal_velocity , max_terminal_velocity)
if Input.is_action_pressed("break") and is_on_floor() :
y_velocity = jump_force
velocity.y = y_velocity
velocity = move_and_slide(velocity , Vector3.UP)
func health_regeneration(delta):
if health <= 999 and health >= 1 :
health += 10 *delta
func onGEMgemcollected():
gem += 1