summaryrefslogtreecommitdiff
path: root/backup_stuff
diff options
context:
space:
mode:
Diffstat (limited to 'backup_stuff')
-rw-r--r--backup_stuff/Player.gd142
-rw-r--r--backup_stuff/Player.tscn57
-rw-r--r--backup_stuff/PlayerOld.tscn37
-rw-r--r--backup_stuff/Player_Other.gd219
-rw-r--r--backup_stuff/Sailor.gd43
-rw-r--r--backup_stuff/Sailor.tscn27
-rw-r--r--backup_stuff/player_controller.gd282
7 files changed, 807 insertions, 0 deletions
diff --git a/backup_stuff/Player.gd b/backup_stuff/Player.gd
new file mode 100644
index 0000000..3555de5
--- /dev/null
+++ b/backup_stuff/Player.gd
@@ -0,0 +1,142 @@
+extends RigidBody
+
+###################-VARIABLES-####################
+
+# Camera
+export(float) var mouse_sensitivity = 12.0
+export(NodePath) var cam_path
+export(NodePath) var ai_follower = null
+export(float) var FOV = 90.0
+var mouse_axis := Vector2()
+onready var cam: Camera = get_node(cam_path)
+# Move
+var velocity := Vector3()
+var direction := Vector3()
+var move_axis := Vector2()
+# Walk
+const FLOOR_MAX_ANGLE: float = deg2rad(46.0)
+export(float) var gravity = 17.35
+export(float) var jump_height = 1.084
+var jump_vel = 5.89#sqrt(2 * gravity * jump_height)
+var is_on_floor : bool = false
+onready var feet = get_node("Feet")
+
+var controlling_vehicle = false
+var vehicle = null
+
+export(float) var acceleration = 70
+export(int) var walk_speed = 6
+export(float) var _airspeed_cap = 1
+export(float) var air_control = 1
+
+# Fly
+export(int) var fly_speed = 50
+export(int) var fly_accel = 10
+var flying := false
+
+# Crouch
+var is_duck = 0
+const duck_height = .5*.6*1.8 #one half the hitbox duck height
+var duck_speed = 2.3
+var knockback_mult = 1
+var duck_progress = 0
+
+var world
+
+# Shoot
+var countdown = 0;
+export(float) var firing_cooldown = .8
+export(Vector3) var snap
+
+static func compare_floats(a, b, epsilon = 0.00001):
+ return abs(a - b) <= epsilon
+
+func walk(delta):
+ knockback_mult = 1.35 if is_duck else 1
+ #check if is on floor
+ if feet.is_colliding():
+ is_on_floor = true
+
+ # Duck
+ if not compare_floats(duck_progress, is_duck):
+ var h = $CollisionBox.get_shape().get_extents().y
+ var dir = -1 if is_duck else 1
+ var dh = dir*duck_speed*state.step
+ var desh = duck_height if is_duck else 0.9
+ if abs(h+dh - desh) < .05:
+ dh = desh-h
+ $CollisionBox.get_shape().set_extents(Vector3(.325,h+dh,.325))
+ $CollisionBox.translate_object_local(Vector3(0,-dh/2,0))
+ duck_progress = 1-(h+dh-duck_height)/(0.9-duck_height)
+
+ # Input
+ direction = Vector3()
+ var aim: Basis = get_global_transform().basis
+ if move_axis.x >= 0.5:
+ direction -= aim.z
+ elif move_axis.x <= -0.5:
+ direction += aim.z
+ if move_axis.y <= -0.5:
+ direction -= aim.x
+ elif move_axis.y >= 0.5:
+ direction += aim.x
+ direction.y = 0
+ direction = direction.normalized()
+
+ # Jump
+ if is_on_floor:
+ snap = Vector3.DOWN
+ if Input.is_action_just_pressed("move_jump"):
+ snap = Vector3.ZERO
+ velocity.y += jump_vel
+
+ velocity.y -= gravity * state.step
+ if abs(velocity.y) > 1:
+ snap = Vector3.ZERO
+
+
+ #max walk speed
+ var _speed = walk_speed if not is_duck else walk_speed*0.5
+
+
+ var _temp_accel: float = acceleration
+
+
+ if not is_on_floor or Input.is_action_just_pressed("move_jump"):
+ _temp_accel *= air_control
+ else: #apply friction
+ var _cspeed = sqrt(pow(velocity.x,2)+pow(velocity.z,2))
+ if _cspeed != 0:
+ var walkdir = Vector2(velocity.x,velocity.z)
+ var fvar = _cspeed*friction if direction.length() != 0 else _cspeed*2*friction
+ #fvar *= 4 if is_duck else 1
+ velocity.x -= walkdir.normalized().x*fvar*state.step
+ velocity.z -= walkdir.normalized().y*fvar*state.step
+
+ var projVel = Vector2(velocity.x,velocity.z).dot(Vector2(direction.x,direction.z))
+ _temp_accel *= state.step
+
+ if is_on_floor:
+ if _speed - (projVel + _temp_accel) > 0:
+ velocity.x += direction.x*_temp_accel
+ velocity.z += direction.z*_temp_accel
+ else:
+ velocity.x += direction.x*(_speed-projVel)
+ velocity.z += direction.z*(_speed-projVel)
+ elif _airspeed_cap - projVel > 0:
+ velocity.x += direction.x*_temp_accel
+ velocity.z += direction.z*_temp_accel
+
+ # clamping (to stop on slopes)
+ if direction.dot(velocity) == 0:
+ var _vel_clamp := 0.25
+ if abs(velocity.x) < _vel_clamp:
+ velocity.x = 0
+ if abs(velocity.z) < _vel_clamp:
+ velocity.z = 0
+
+ # Move
+ print(velocity)
+ set_linear_velocity(velocity)
+ velocity = get_linear_velocity()
+
diff --git a/backup_stuff/Player.tscn b/backup_stuff/Player.tscn
new file mode 100644
index 0000000..a68f994
--- /dev/null
+++ b/backup_stuff/Player.tscn
@@ -0,0 +1,57 @@
+[gd_scene load_steps=3 format=2]
+
+[ext_resource path="res://backup_stuff/Player.gd" type="Script" id=1]
+
+[sub_resource type="CylinderShape" id=1]
+height = 1.8
+radius = 0.4
+
+[node name="Player" type="RigidBody"]
+mode = 2
+mass = 80.0
+contacts_reported = 1
+contact_monitor = true
+axis_lock_angular_x = true
+axis_lock_angular_z = true
+script = ExtResource( 1 )
+mouse_sensitivity = null
+cam_path = null
+ai_follower = null
+FOV = null
+gravity = null
+jump_height = null
+acceleration = null
+walk_speed = null
+_airspeed_cap = null
+air_control = null
+fly_speed = null
+fly_accel = null
+firing_cooldown = null
+snap = null
+
+[node name="CollisionBox" type="CollisionShape" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.875, 0 )
+shape = SubResource( 1 )
+
+[node name="Camera" type="Camera" parent="."]
+transform = Transform( 1, 0, 0, 0, 0.999973, -0.00740013, 0, 0.00740013, 0.999973, 0, 1.5, 0 )
+cull_mask = 524287
+near = 0.15
+far = 8192.0
+
+[node name="UseRay" type="RayCast" parent="Camera"]
+enabled = true
+cast_to = Vector3( 0, 0, -2.5 )
+collision_mask = 131075
+collide_with_areas = true
+
+[node name="MeleeRay" type="RayCast" parent="Camera"]
+enabled = true
+cast_to = Vector3( 0, 0, -2.5 )
+collision_mask = 262145
+collide_with_areas = true
+
+[node name="Feet" type="RayCast" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0608446, 0 )
+enabled = true
+cast_to = Vector3( 0, -0.25, 0 )
diff --git a/backup_stuff/PlayerOld.tscn b/backup_stuff/PlayerOld.tscn
new file mode 100644
index 0000000..f79339e
--- /dev/null
+++ b/backup_stuff/PlayerOld.tscn
@@ -0,0 +1,37 @@
+[gd_scene load_steps=3 format=2]
+
+[ext_resource path="res://backup_stuff/player_controller.gd" type="Script" id=1]
+
+[sub_resource type="BoxShape" id=1]
+extents = Vector3( 0.325, 0.9, 0.325 )
+
+[node name="Player" type="KinematicBody" groups=["units"]]
+script = ExtResource( 1 )
+cam_path = NodePath("Camera")
+jump_height = 2.0
+fly_speed = 10
+
+[node name="CollisionBox" type="CollisionShape" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.875, 0 )
+shape = SubResource( 1 )
+
+[node name="Camera" type="Camera" parent="."]
+transform = Transform( 1, 0, 0, 0, 0.999973, -0.00740013, 0, 0.00740013, 0.999973, 0, 1.5, 0 )
+cull_mask = 524287
+near = 0.15
+far = 8192.0
+
+[node name="UseRay" type="RayCast" parent="Camera"]
+enabled = true
+cast_to = Vector3( 0, 0, -2.5 )
+collision_mask = 131075
+collide_with_areas = true
+
+[node name="MeleeRay" type="RayCast" parent="Camera"]
+enabled = true
+cast_to = Vector3( 0, 0, -100 )
+collision_mask = 262145
+collide_with_areas = true
+
+[node name="TugPoint" type="Spatial" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.30489, -1.57084 )
diff --git a/backup_stuff/Player_Other.gd b/backup_stuff/Player_Other.gd
new file mode 100644
index 0000000..0116d71
--- /dev/null
+++ b/backup_stuff/Player_Other.gd
@@ -0,0 +1,219 @@
+extends KinematicBody
+
+
+export(String, "red", "blue") var team
+#item variables
+var can_swap = true
+var has_items = [false,false,false,false,false]
+var items = [null,null,null,null,null]
+export(String) var item0path
+export(String) var item1path
+export(String) var item2path
+export(String) var item3path
+export(String) var item4path
+var weapon
+export(int) var health = 100
+
+var unit
+
+var move_axis := Vector2()
+var velocity := Vector3()
+var direction := Vector3()
+var parentvel := Vector3()
+var tugging = false
+var tug_target
+
+export(float) var friction = 4
+export(float) var _airspeed_cap = 1
+
+var is_duck = 0
+const duck_height = .5*.6*1.8 #one half the hitbox duck height
+var duck_speed = 2.3
+var knockback_mult = 1
+var duck_progress = 0
+
+var can_switch = true
+
+
+const gravity = 9.8
+const FLOOR_MAX_ANGLE: float = deg2rad(46.0)
+const jump_constant = 12
+const walk_speed = 6
+const tug_speed = 1.5
+const acceleration = 70
+const air_control = 0.3
+const tug_force = 500
+const tug_distance = 3.5
+const push_distance = 1
+const duck_knockback_mult = 1.35
+const jump_vel = 5
+
+static func compare_floats(a, b, epsilon = 0.00001):
+ return abs(a - b) <= epsilon
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ $Camera/UseRay.add_exception(self)
+ $Camera/MeleeRay.add_exception(self)
+
+
+func damage(amount, attacker, point = Vector3.ZERO):
+ health -= amount
+ rpc("update_health",health)
+ if health <= 0:
+ if is_network_master():
+ get_node("/root/Game/Camera").current = true
+ rpc("die")
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _process(delta):
+ if is_network_master() and !get_node('/root/Game/HUD/Selection').is_visible_in_tree():
+ if Input.is_action_just_pressed("use"):
+ pass
+ move_axis.x = Input.get_action_strength("walk_forward") - Input.get_action_strength("walk_backward")
+ move_axis.y = Input.get_action_strength("strafe_right") - Input.get_action_strength("strafe_left")
+ is_duck = Input.get_action_strength("duck")
+ if Input.is_action_just_pressed("attack1"):
+ weapon.attack()
+ if Input.is_action_just_pressed("attack2"):
+ weapon.attack2()
+ if Input.is_action_just_pressed("slot1"):
+ rpc('switch_weapon',0)
+ if Input.is_action_just_pressed("slot2"):
+ rpc('switch_weapon',1)
+
+func initiate_use():
+ if tugging:
+ tugging = false
+ elif $Camera/UseRay.is_colliding():
+ var type = $Camera/UseRay.get_collider().name
+ match type:
+ "TugArea":
+ tugging = true
+ tug_target = $Camera/UseRay.get_collider().get_parent()
+ _:
+ pass
+
+func check_tug():
+ if !$Camera/UseRay.is_colliding() or !($Camera/UseRay.get_collider().name != tug_target.name):
+ tugging = false
+
+func _physics_process(delta):
+ if is_network_master() or (get_tree().get_network_unique_id() == 1 and get_network_master() == -1):
+ if is_network_master():
+ player_move(delta)
+ else:
+ ai_move(delta)
+ rpc("_set_position", global_transform)
+
+remotesync func update_health(new_h):
+ health = new_h
+ if is_network_master():
+ get_tree().get_root().get_node('Game/HUD/Health').text = str(health)
+
+func ai_move(delta):
+ if !is_on_floor():
+ velocity.y -= gravity * delta
+ move_and_slide(velocity,Vector3.UP)
+
+func player_move(delta):
+ # Input
+ direction = Vector3()
+ var aim: Basis = get_global_transform().basis
+ if move_axis.x >= 0.5:
+ direction -= aim.z
+ elif move_axis.x <= -0.5:
+ direction += aim.z
+ if move_axis.y <= -0.5:
+ direction -= aim.x
+ elif move_axis.y >= 0.5:
+ direction += aim.x
+ direction.y = 0
+ direction = direction.normalized()
+
+ # Jump
+ var snap = Vector3.ZERO
+ if is_on_floor():
+ snap = Vector3.DOWN
+ if Input.is_action_just_pressed("jump"):
+ snap = Vector3.ZERO
+ velocity.y += jump_vel
+ else:
+ velocity += parentvel
+
+ velocity.y -= gravity * delta
+ if abs(velocity.y) > 1:
+ snap = Vector3.ZERO
+
+ #max walk speed
+ var _speed = walk_speed if not is_duck else walk_speed*0.5
+
+ var _temp_accel: float = acceleration
+
+ if is_on_floor():
+ var _cspeed = sqrt(pow(velocity.x,2)+pow(velocity.z,2))
+ if _cspeed != 0:
+ var walkdir = Vector2(velocity.x,velocity.z)
+ var fvar = _cspeed*friction if direction.length() != 0 else _cspeed*2*friction
+ #fvar *= 4 if is_duck else 1
+ velocity.x -= walkdir.normalized().x*fvar*delta
+ velocity.z -= walkdir.normalized().y*fvar*delta
+ animationcontroller.rpc("run",_cspeed/walk_speed)
+ else:
+ animationcontroller.rpc("run",0)
+ #rpc("_play_animation",false,"idle_single")
+
+ var projVel = Vector2(velocity.x,velocity.z).dot(Vector2(direction.x,direction.z))
+ _temp_accel *= delta
+
+ if is_on_floor():
+
+ if _speed - (projVel + _temp_accel) > 0:
+ velocity.x += direction.x*_temp_accel
+ velocity.z += direction.z*_temp_accel
+ else:
+ velocity.x += direction.x*(_speed-projVel)
+ velocity.z += direction.z*(_speed-projVel)
+ elif _airspeed_cap - projVel > 0:
+ velocity.x += direction.x*_temp_accel
+ velocity.z += direction.z*_temp_accel
+
+ # clamping (to stop on slopes)
+ if direction.dot(velocity) == 0:
+ var _vel_clamp := 0.25
+ if abs(velocity.x) < _vel_clamp:
+ velocity.x = 0
+ if abs(velocity.z) < _vel_clamp:
+ velocity.z = 0
+
+ # Move
+ var moving = move_and_slide_with_snap(velocity, snap, Vector3.UP, false, 4, FLOOR_MAX_ANGLE)
+ if is_on_wall():
+ velocity = moving
+ else:
+ velocity.y = moving.y
+
+remotesync func die():
+ get_node("/root/Game").update_chars_delay()
+ queue_free()
+
+
+remote func _set_position(pos):
+ global_transform = pos
+#set net master of this player to the id
+func _set_master(id):
+ if get_network_master() == -1:
+ $Camera.current = true
+ $Armature/Skeleton/Cube.set_layer_mask(524288)
+ for unit in get_tree().get_nodes_in_group("units"):
+ if unit.get_network_master() == id:
+ unit.rpc("_set_master_helper",-1)
+ #nit.set_network_master(-1)
+ rpc("_set_master_helper", id)
+remotesync func _set_master_helper(id):
+ set_network_master(id)
+ update_health(health)
+ if id == -1:
+ $Armature/Skeleton/Cube.set_layer_mask(1)
+ get_node("/root/Game").update_chars()
diff --git a/backup_stuff/Sailor.gd b/backup_stuff/Sailor.gd
new file mode 100644
index 0000000..24b93f9
--- /dev/null
+++ b/backup_stuff/Sailor.gd
@@ -0,0 +1,43 @@
+extends KinematicBody
+
+
+# Declare member variables here. Examples:
+# var a = 2
+# var b = "text"
+export(NodePath) var parent_vehicle = null
+#onready var nav_agent : NavigationAgent = get_node("NavigationAgent")
+var parent_vehicle_nav = null
+
+var destination = Vector3.ZERO
+var closest_point = Vector3.ZERO
+var direction = Vector3.ZERO
+var path = null
+var pathfinding = false
+
+const speed = 5
+var velocity = Vector3.ZERO
+
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ if parent_vehicle != null:
+ parent_vehicle = get_node(parent_vehicle)
+ parent_vehicle_nav = parent_vehicle.get_node("Navigation")
+ #nav_agent.set_navigation(parent_vehicle_nav)
+
+func update_destination(new_dest):
+ pass#nav_agent.set_target_location(new_dest)
+
+func move(delta):
+ var target = Vector3.ZERO#nav_agent.get_next_location()
+ var direction : Vector3 = (target - global_transform.origin).normalized() * speed
+ velocity.y -= 9.8*delta
+ velocity.x = direction.normalized().x*speed
+ velocity.z = direction.normalized().z*speed
+ #nav_agent.set_velocity(Vector3(velocity.x,0,velocity.z))
+ velocity = move_and_slide(velocity, Vector3.UP, true, 4, 0.785, false)
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _physics_process(delta):
+ move(delta)
diff --git a/backup_stuff/Sailor.tscn b/backup_stuff/Sailor.tscn
new file mode 100644
index 0000000..6458fec
--- /dev/null
+++ b/backup_stuff/Sailor.tscn
@@ -0,0 +1,27 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://backup_stuff/Sailor.gd" type="Script" id=1]
+
+[sub_resource type="BoxShape" id=1]
+extents = Vector3( 0.325, 0.9, 0.325 )
+
+[sub_resource type="CubeMesh" id=2]
+size = Vector3( 0.625, 1.8, 0.625 )
+
+[node name="Sailor" type="KinematicBody"]
+collision/safe_margin = 0.01
+script = ExtResource( 1 )
+
+[node name="CollisionShape" type="CollisionShape" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.937097, 0 )
+shape = SubResource( 1 )
+
+[node name="MeshInstance" type="MeshInstance" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.937097, 0 )
+mesh = SubResource( 2 )
+
+[node name="NavigationAgent" type="NavigationAgent" parent="."]
+target_desired_distance = 3.52
+agent_height_offset = 0.1
+radius = 0.5
+max_speed = 5.0
diff --git a/backup_stuff/player_controller.gd b/backup_stuff/player_controller.gd
new file mode 100644
index 0000000..f52decf
--- /dev/null
+++ b/backup_stuff/player_controller.gd
@@ -0,0 +1,282 @@
+extends KinematicBody
+
+###################-VARIABLES-####################
+
+# Camera
+export(float) var mouse_sensitivity = 12.0
+export(NodePath) var cam_path
+export(NodePath) var ai_follower = null
+export(float) var FOV = 90.0
+var mouse_axis := Vector2()
+onready var cam: Camera = get_node(cam_path)
+# Move
+var velocity := Vector3()
+var direction := Vector3()
+var move_axis := Vector2()
+# Walk
+const FLOOR_MAX_ANGLE: float = deg2rad(46.0)
+export(float) var gravity = 17.35
+export(float) var jump_height = 1.084
+var jump_vel = 5.89#sqrt(2 * gravity * jump_height)
+
+var has_control = true
+var vehicle = null
+
+export(float) var acceleration = 70
+export(int) var walk_speed = 6
+export(float) var _airspeed_cap = 1
+export(float) var friction = 4
+export(float) var air_control = 1
+
+var grappling = false
+var grapple_length = 0
+var grapple_point = Vector3.ZERO
+
+# Fly
+export(int) var fly_speed = 50
+export(int) var fly_accel = 10
+var flying := false
+
+# Crouch
+var is_duck = 0
+const duck_height = .5*.6*1.8 #one half the hitbox duck height
+var duck_speed = 2.3
+var knockback_mult = 1
+var duck_progress = 0
+
+var world
+
+# Shoot
+var countdown = 0;
+export(float) var firing_cooldown = .8
+export(Vector3) var snap
+
+
+##################################################
+
+# Called when the node enters the scene tree
+func _ready() -> void:
+ if ai_follower != null:
+ ai_follower = get_node(ai_follower)
+ flying = true
+ Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
+ cam.fov = FOV
+ $Camera/UseRay.add_exception(self)
+ $Camera/MeleeRay.add_exception(self)
+ world = get_parent()
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame
+func _process(_delta: float) -> void:
+ if Input.is_action_just_pressed("use"):
+ initiate_use()
+ if !has_control:
+ return
+ if Input.is_action_just_pressed("fly"):
+ flying = !flying
+ if Input.is_action_just_pressed("fire"):
+ if $Camera/MeleeRay.is_colliding():
+ grappling = true
+ grapple_point = $Camera/MeleeRay.get_collision_point()
+ grapple_length = (grapple_point-global_transform.origin).length() + 1
+ elif Input.is_action_just_released("fire"):
+ grappling = false
+ if Input.is_action_just_pressed("altfire"):
+ cam.fov = 20 if cam.fov == FOV else FOV
+ if countdown > 0:
+ countdown -= _delta
+ move_axis.x = Input.get_action_strength("move_forward") - Input.get_action_strength("move_backward")
+ move_axis.y = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
+ is_duck = Input.get_action_strength("duck")
+
+
+# Called every physics tick. 'delta' is constant
+func _physics_process(delta: float) -> void:
+ if !has_control:
+ move_axis = Vector2.ZERO
+ if flying:
+ fly(delta)
+ else:
+ walk(delta)
+
+static func compare_floats(a, b, epsilon = 0.00001):
+ return abs(a - b) <= epsilon
+
+func regain_control(gt):
+ #world.add_child(self)
+ global_transform.origin = gt
+ has_control = true
+ vehicle = null
+
+func initiate_use():
+ if !has_control:
+ vehicle.relinquish_control()
+ return
+ if $Camera/UseRay.is_colliding():
+ var type = $Camera/UseRay.get_collider().name
+ match type:
+ "SteerArea":
+ if flying or $Camera/UseRay.get_collider().get_parent().is_in_use():
+ return
+ has_control = false
+ vehicle = $Camera/UseRay.get_collider().get_parent().take_control(self)
+ var gt = global_transform.origin
+ velocity = Vector3.ZERO
+ #get_parent().remove_child(self)
+ #vehicle.add_child(self)
+ global_transform.origin = gt
+ _:
+ pass
+
+# Called when there is an input event
+func _input(event: InputEvent) -> void:
+ if event is InputEventMouseMotion:
+ mouse_axis = event.relative
+ camera_rotation()
+
+
+func walk(delta: float) -> void:
+ knockback_mult = 1.35 if is_duck else 1
+ if grappling:
+ var grapple_vec = global_transform.origin - grapple_point
+ var grapple_dist = grapple_vec.length()
+ if grapple_dist >= grapple_length:
+ velocity -= grapple_vec.dot(velocity)*grapple_vec/(grapple_dist*grapple_dist)
+ var v = velocity.abs()
+ velocity -= grapple_vec.normalized()*delta*v*v/grapple_dist
+ # Duck
+ if not compare_floats(duck_progress, is_duck):
+ var h = $CollisionBox.get_shape().get_extents().y
+ var dir = -1 if is_duck else 1
+ var dh = dir*duck_speed*delta
+ var desh = duck_height if is_duck else 0.9
+ if abs(h+dh - desh) < .05:
+ dh = desh-h
+ $CollisionBox.get_shape().set_extents(Vector3(.325,h+dh,.325))
+ $CollisionBox.translate_object_local(Vector3(0,-dh/2,0))
+ duck_progress = 1-(h+dh-duck_height)/(0.9-duck_height)
+
+ # Input
+ direction = Vector3()
+ var aim: Basis = get_global_transform().basis
+ if move_axis.x >= 0.5:
+ direction -= aim.z
+ elif move_axis.x <= -0.5:
+ direction += aim.z
+ if move_axis.y <= -0.5:
+ direction -= aim.x
+ elif move_axis.y >= 0.5:
+ direction += aim.x
+ direction.y = 0
+ direction = direction.normalized()
+
+ # Jump
+ if is_on_floor():
+ snap = Vector3.DOWN
+ if Input.is_action_just_pressed("move_jump"):
+ snap = Vector3.ZERO
+ velocity.y += jump_vel
+
+ velocity.y -= gravity * delta
+ if abs(velocity.y) > 1:
+ snap = Vector3.ZERO
+
+
+ #max walk speed
+ var _speed = walk_speed if not is_duck else walk_speed*0.5
+
+
+ var _temp_accel: float = acceleration
+
+
+ if not is_on_floor() or Input.is_action_just_pressed("move_jump"):
+ _temp_accel *= air_control
+ else: #apply friction
+ var _cspeed = sqrt(pow(velocity.x,2)+pow(velocity.z,2))
+ if _cspeed != 0:
+ var walkdir = Vector2(velocity.x,velocity.z)
+ var fvar = _cspeed*friction if direction.length() != 0 else _cspeed*2*friction
+ #fvar *= 4 if is_duck else 1
+ velocity.x -= walkdir.normalized().x*fvar*delta
+ velocity.z -= walkdir.normalized().y*fvar*delta
+
+ var projVel = Vector2(velocity.x,velocity.z).dot(Vector2(direction.x,direction.z))
+ _temp_accel *= delta
+
+ if is_on_floor():
+ if _speed - (projVel + _temp_accel) > 0:
+ velocity.x += direction.x*_temp_accel
+ velocity.z += direction.z*_temp_accel
+ else:
+ velocity.x += direction.x*(_speed-projVel)
+ velocity.z += direction.z*(_speed-projVel)
+ elif _airspeed_cap - projVel > 0:
+ velocity.x += direction.x*_temp_accel
+ velocity.z += direction.z*_temp_accel
+
+
+
+
+ # clamping (to stop on slopes)
+ if direction.dot(velocity) == 0:
+ var _vel_clamp := 0.25
+ if abs(velocity.x) < _vel_clamp:
+ velocity.x = 0
+ if abs(velocity.z) < _vel_clamp:
+ velocity.z = 0
+
+ # Move
+ var landed = is_on_floor() == false
+ #remove_collision_exception_with(rigid_body)
+ var moving = move_and_slide_with_snap(velocity, snap,Vector3.UP, true, 4, FLOOR_MAX_ANGLE, false)
+ landed = landed and is_on_floor()
+# if is_on_wall():
+# #velocity.x = moving.x
+# #velocity.z = moving.z
+# velocity = moving
+ if landed:
+ velocity -= get_slide_collision(0).collider_velocity
+ else:
+ velocity = moving
+
+
+
+func fly(delta: float) -> void:
+ # Input
+ direction = Vector3()
+ var aim = cam.get_global_transform().basis
+ if move_axis.x >= 0.5:
+ direction -= aim.z
+ elif move_axis.x <= -0.5:
+ direction += aim.z
+ if move_axis.y <= -0.5:
+ direction -= aim.x
+ elif move_axis.y >= 0.5:
+ direction += aim.x
+ direction = direction.normalized()
+
+ # Acceleration and Deacceleration
+ var target: Vector3 = direction * 300
+ velocity = velocity.linear_interpolate(target, fly_accel * delta)
+
+ # Move
+ velocity = move_and_slide(velocity, Vector3.UP, false, 4, 45.0, false)
+
+
+func camera_rotation() -> void:
+ if Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED:
+ return
+ if mouse_axis.length() > 0:
+ var horizontal: float = -mouse_axis.x * (mouse_sensitivity / 100)
+ var vertical: float = -mouse_axis.y * (mouse_sensitivity / 100)
+
+ mouse_axis = Vector2()
+
+ rotate_y(deg2rad(horizontal))
+ cam.rotate_x(deg2rad(vertical))
+
+ # Clamp mouse rotation
+ var temp_rot: Vector3 = cam.rotation_degrees
+ temp_rot.x = clamp(temp_rot.x, -90, 90)
+ cam.rotation_degrees = temp_rot
+