[gd_scene load_steps=20 format=2]

[sub_resource type="GDScript" id=3]
resource_name = "Player"
script/source = "extends KinematicBody
 
export var move_speed := 12.0
export var jump_force := 30.0

export var gravity := 0.98
export var max_fall_speed := 30
 
export var look_sens_h := 0.2

var is_on_floor_prev := false

onready var anim = $Mesh/AnimationPlayer
 
var y_velo = 0

func _ready():
	anim.get_animation(\"walk\").set_loop(true)
 
func _input(event):
	if event is InputEventMouseMotion:
		rotation_degrees.y -= event.relative.x * look_sens_h
		
	if event.is_action_pressed(\"ui_end\"):
		global_translation = Vector3.ZERO
 
func _physics_process(_delta):
	var move_vec = Vector3()
	if Input.is_action_pressed(\"move_forward\"):
		move_vec.z -= 1
	if Input.is_action_pressed(\"move_backwards\"):
		move_vec.z += 1
	if Input.is_action_pressed(\"move_right\"):
		move_vec.x += 1
	if Input.is_action_pressed(\"move_left\"):
		move_vec.x -= 1
	
	move_vec = move_vec.normalized()
	move_vec = move_vec.rotated(Vector3(0, 1, 0), rotation.y)
	move_vec *= move_speed
	move_vec.y = y_velo
	
	var _vel:Vector3 = move_and_slide(move_vec, Vector3(0, 1, 0))
	
	# questionable???
	if is_on_floor_prev and not is_on_floor():
		$CoyoteJump.start()
	is_on_floor_prev = is_on_floor()
	
	var grounded :bool= is_on_floor() or not $CoyoteJump.is_stopped() 
	
	y_velo -= gravity
	
	var just_jumped := false
	
	if Input.is_action_just_pressed(\"jump\") and grounded:
		just_jumped = true
		y_velo = jump_force
	
	if grounded and y_velo <= 0:
		y_velo = -0.1
	
	if y_velo < -max_fall_speed:
		y_velo = -max_fall_speed
 
	if just_jumped:
		play_anim(\"jump\")
	elif grounded:
		if move_vec.x == 0 and move_vec.z == 0:
			play_anim(\"idle\")
		else:
			play_anim(\"walk\")
 
func play_anim(name):
	if anim.current_animation == name:
		return
	anim.play(name)
"

[sub_resource type="CapsuleShape" id=4]
radius = 0.202191
height = 1.09113

[sub_resource type="CylinderShape" id=32]
height = 0.224826
radius = 0.194837

[sub_resource type="GDScript" id=11]
resource_name = "Camera"
script/source = "extends Spatial

export var look_sens_v := 0.5

#this will not work
export(float) onready var not_working := 0.1

func _ready() -> void:
	pass

func _input(event):
	if event is InputEventMouseMotion:
		rotation_degrees.x -= event.relative.y * look_sens_v
		rotation_degrees.x = clamp(rotation_degrees.x, -90, 90)
		
	if event is InputEventMouseButton:
		Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
	
	if event.is_action_pressed(\"ui_focus_next\"):
		Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
"

[sub_resource type="CylinderMesh" id=31]
radial_segments = 8
rings = 0

[sub_resource type="SpatialMaterial" id=33]
albedo_color = Color( 0.08, 0.08, 0.08, 1 )
roughness = 0.73

[sub_resource type="QuadMesh" id=34]
size = Vector2( 0.3, 0.5 )

[sub_resource type="SpatialMaterial" id=35]
emission_enabled = true
emission = Color( 0.95, 0.95, 0.95, 1 )
emission_energy = 10.0
emission_operator = 0
emission_on_uv2 = false

[sub_resource type="SpatialMaterial" id=19]
params_cull_mode = 2
albedo_color = Color( 0.752941, 0, 0, 1 )

[sub_resource type="Animation" id=6]
length = 0.001
tracks/0/type = "value"
tracks/0/path = NodePath("Body:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ Vector3( 1, 1, 1 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Body:translation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ Vector3( 0, 0.744519, 0 ) ]
}

[sub_resource type="Animation" id=7]
resource_name = "idle"
length = 2.0
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath("Body:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 1, 2 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Vector3( 1, 1, 1 ), Vector3( 1.1, 1.1, 1 ), Vector3( 1, 1, 1 ) ]
}

[sub_resource type="Animation" id=8]
resource_name = "jump"
length = 0.6
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath("Body:scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.3, 0.6 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Vector3( 1.07, 1.07, 1 ), Vector3( 1.07, 1.07, 1.07262 ), Vector3( 1.07, 1.07, 1 ) ]
}

[sub_resource type="Animation" id=9]
resource_name = "walk"
length = 0.4
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath("Body:translation")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4 ),
"transitions": PoolRealArray( 1, 1, 1, 1, 1 ),
"update": 0,
"values": [ Vector3( 0, 0.744519, 0 ), Vector3( 0, 0.763796, 0 ), Vector3( 0, 0.744519, 0 ), Vector3( 0, 0.763796, 0 ), Vector3( 0, 0.744519, 0 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("Body:rotation_degrees:z")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.1, 0.3, 0.4 ),
"transitions": PoolRealArray( 1, 1, 1, 1 ),
"update": 0,
"values": [ 0.0, 10.0, -10.0, 0.0 ]
}

[sub_resource type="PlaneMesh" id=18]
material = SubResource( 19 )
size = Vector2( 0.16, 1.6 )
subdivide_depth = 8

[sub_resource type="GDScript" id=17]
resource_name = "Shadow"
script/source = "extends Spatial

export var offset := 0.25

func _process(_delta) -> void:
	
	var collide :bool= $RayCast.is_colliding()
	
	$Circle.visible = collide
	
	if collide:
		var py:float = $RayCast.get_collision_point().y
		
		$Circle.global_translation.y = py + offset

"

[sub_resource type="Gradient" id=13]
offsets = PoolRealArray( 0.103704, 0.422222, 0.766667 )
colors = PoolColorArray( 0, 0, 0, 1, 0, 0, 0, 0.447059, 0, 0, 0, 0 )

[sub_resource type="GradientTexture2D" id=14]
gradient = SubResource( 13 )
width = 32
height = 32
fill = 1
fill_from = Vector2( 0.5, 0.5 )
fill_to = Vector2( 1, 0.5 )

[sub_resource type="SpatialMaterial" id=15]
flags_transparent = true
flags_unshaded = true
albedo_texture = SubResource( 14 )

[sub_resource type="QuadMesh" id=16]
material = SubResource( 15 )
size = Vector2( 0.75, 0.75 )

[node name="Player" type="KinematicBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 2 )
collision_layer = 2
script = SubResource( 3 )
move_speed = 3.2
jump_force = 20.0
gravity = 1.2

[node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0.724957, 0 )
shape = SubResource( 4 )

[node name="CollisionShape2" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.884122, 0 )
shape = SubResource( 32 )

[node name="CamRoot" type="Spatial" parent="."]
script = SubResource( 11 )

[node name="Camera" type="ClippedCamera" parent="CamRoot"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2, 4 )
current = true
margin = 0.1
process_mode = 1

[node name="Mesh" type="Spatial" parent="."]

[node name="Body" type="Spatial" parent="Mesh"]
transform = Transform( 0.976315, -0.216353, 9.45709e-09, 0, -4.37114e-08, -1, 0.216353, 0.976315, -4.26761e-08, 0, 0.744519, 0 )

[node name="Body" type="MeshInstance" parent="Mesh/Body"]
transform = Transform( 0.195555, 0, 0, 0, -1.04907e-08, 0.135018, 0, -0.24, -5.90182e-09, 0, 0, 0 )
mesh = SubResource( 31 )
material/0 = SubResource( 33 )

[node name="Body2" type="MeshInstance" parent="Mesh/Body"]
transform = Transform( 0.0876868, 0, 0, 0, -1.1745e-08, -0.0631662, 0, 0.268694, -2.76108e-09, -0.122125, 0.049392, 0.057337 )
mesh = SubResource( 31 )
material/0 = SubResource( 33 )

[node name="Body3" type="MeshInstance" parent="Mesh/Body"]
transform = Transform( 0.0876868, 0, 0, 0, -1.1745e-08, -0.0631662, 0, 0.268694, -2.76108e-09, 0.123573, 0.0493927, 0.0573372 )
mesh = SubResource( 31 )
material/0 = SubResource( 33 )

[node name="head" type="MeshInstance" parent="Mesh/Body"]
transform = Transform( 0.088, 0, 0, 0, -4.19629e-09, 0.08, 0, -0.096, -3.49691e-09, 0, 0, -0.339126 )
mesh = SubResource( 31 )
material/0 = SubResource( 33 )

[node name="eye_left" type="MeshInstance" parent="Mesh/Body/head"]
transform = Transform( 1, 0, 0, 0, -1, 8.74228e-08, 0, -8.74228e-08, -1, 0.568194, 0.255432, -1.05656 )
mesh = SubResource( 34 )
material/0 = SubResource( 35 )

[node name="eye_right" type="MeshInstance" parent="Mesh/Body/head"]
transform = Transform( 1, 0, 0, 0, -1, 8.74228e-08, 0, -8.74228e-08, -1, -0.365176, 0.255432, -1.05656 )
mesh = SubResource( 34 )
material/0 = SubResource( 35 )

[node name="OmniLight" type="SpotLight" parent="Mesh/Body/head"]
transform = Transform( 11.3636, 0, 0, 0, 10.4167, -2.21659e-13, 0, 2.1684e-19, 12.5, 0, 0.257117, -0.572075 )
light_energy = 0.75
spot_range = 4.51976
spot_attenuation = 1.31951
spot_angle = 66.4019

[node name="hat_top" type="MeshInstance" parent="Mesh/Body"]
transform = Transform( 0.1056, 0, 0, 0, -5.03555e-09, 0.096, 0, -0.1152, -4.19629e-09, 0, 0, -0.578262 )
mesh = SubResource( 31 )
material/0 = SubResource( 33 )

[node name="hat_bottom" type="MeshInstance" parent="Mesh/Body"]
transform = Transform( 0.2024, 0, 0, 0, -1.25889e-09, 0.184, 0, -0.0288, -8.0429e-09, 0, 0, -0.464094 )
mesh = SubResource( 31 )
material/0 = SubResource( 33 )

[node name="scarf" type="MeshInstance" parent="Mesh/Body"]
transform = Transform( 0.17204, 0, 0, 0, -1.39107e-09, 0.1564, 0, -0.031824, -6.83646e-09, 0, 0, -0.271663 )
mesh = SubResource( 31 )
material/0 = SubResource( 19 )

[node name="LegR" type="CSGCylinder" parent="Mesh/Body"]
transform = Transform( 0.99863, -0.0659433, 1.81562e-09, 0, -5.50763e-08, -0.793651, 0.052336, 1.25827, -3.4644e-08, 0.0637822, 0, 0.548993 )
radius = 0.1
height = 0.5
cone = true
material = SubResource( 33 )

[node name="LegL" type="CSGCylinder" parent="Mesh/Body"]
transform = Transform( 0.99863, 0.0659433, -1.81562e-09, 0, -5.50763e-08, -0.793651, -0.052336, 1.25827, -3.4644e-08, -0.0650757, 0, 0.548993 )
radius = 0.1
height = 0.5
cone = true
material = SubResource( 33 )

[node name="AnimationPlayer" type="AnimationPlayer" parent="Mesh"]
anims/RESET = SubResource( 6 )
anims/idle = SubResource( 7 )
anims/jump = SubResource( 8 )
anims/walk = SubResource( 9 )

[node name="SoftBody" type="SoftBody" parent="."]
transform = Transform( -1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 1.04064, 0.928791 )
mesh = SubResource( 18 )
collision_layer = 2
collision_mask = 3
damping_coefficient = 0.1
drag_coefficient = 0.1
ray_pickable = false
pinned_points = [ 0, 1 ]
attachments/0/point_index = 0
attachments/0/spatial_attachment_path = NodePath("..")
attachments/0/offset = Vector3( -0.0800001, 1.04064, 0.128791 )
attachments/1/point_index = 1
attachments/1/spatial_attachment_path = NodePath("..")
attachments/1/offset = Vector3( 0.0799999, 1.04064, 0.128791 )

[node name="Shadow" type="Spatial" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.02, 0 )
script = SubResource( 17 )
offset = 0.02

[node name="Circle" type="MeshInstance" parent="Shadow"]
transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0 )
mesh = SubResource( 16 )
skeleton = NodePath("../..")

[node name="RayCast" type="RayCast" parent="Shadow"]
enabled = true
cast_to = Vector3( 0, -50, 0 )

[node name="CoyoteJump" type="Timer" parent="."]
wait_time = 0.16
one_shot = true
