Re-implemented zooming (without division by zero) and a test implementation of stair climbing
parent
6316952ca5
commit
43d91e2e98
|
@ -3,8 +3,26 @@ extends KinematicBody3D
|
||||||
@export var mouse_sensitivity := 0.35
|
@export var mouse_sensitivity := 0.35
|
||||||
#var speed := 15
|
#var speed := 15
|
||||||
|
|
||||||
|
@onready var hud = get_tree().root.find_node("HUD", true, false)
|
||||||
|
@onready var crosshair = hud.get_node("Crosshair")
|
||||||
@onready var head = $Head
|
@onready var head = $Head
|
||||||
|
@onready var camera = $Head/Camera
|
||||||
|
@onready var tween = $Head/Camera/Tween
|
||||||
|
|
||||||
@onready var ground_check = $GroundCheck
|
@onready var ground_check = $GroundCheck
|
||||||
|
@onready var climb_tween = $ClimbTween
|
||||||
|
@onready var climb_check = $ClimbCheck
|
||||||
|
@onready var body = $Body
|
||||||
|
|
||||||
|
|
||||||
|
var base_fov = 90
|
||||||
|
var view_zoom := 1.0 :
|
||||||
|
set(zoom):
|
||||||
|
view_zoom = zoom
|
||||||
|
camera.fov = base_fov / zoom
|
||||||
|
crosshair.modulate.a = 1 - (zoom - 1)
|
||||||
|
|
||||||
|
var climb_height := 1
|
||||||
|
|
||||||
var direction := Vector3.ZERO
|
var direction := Vector3.ZERO
|
||||||
var accel := 0
|
var accel := 0
|
||||||
|
@ -16,9 +34,9 @@ var accel_type := {
|
||||||
"water": 4
|
"water": 4
|
||||||
}
|
}
|
||||||
var speed_type := {
|
var speed_type := {
|
||||||
"ground": 15,
|
"ground": 10,
|
||||||
"air": 15,
|
"air": 10,
|
||||||
"water": 7.5
|
"water": 5
|
||||||
}
|
}
|
||||||
var gravity := 28
|
var gravity := 28
|
||||||
var jump := 14
|
var jump := 14
|
||||||
|
@ -31,15 +49,16 @@ var snap := Vector3.ZERO
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
|
view_zoom = 1.0
|
||||||
|
|
||||||
func aim(event) -> void:
|
func aim(event) -> void:
|
||||||
var mouse_motion = event as InputEventMouseMotion
|
var mouse_motion = event as InputEventMouseMotion
|
||||||
|
|
||||||
if mouse_motion:
|
if mouse_motion:
|
||||||
rotation_degrees.y -= mouse_motion.relative.x * mouse_sensitivity
|
rotation_degrees.y -= mouse_motion.relative.x * mouse_sensitivity / view_zoom
|
||||||
|
|
||||||
var current_tilt: float = head.rotation_degrees.x
|
var current_tilt: float = head.rotation_degrees.x
|
||||||
current_tilt -= mouse_motion.relative.y * mouse_sensitivity
|
current_tilt -= mouse_motion.relative.y * mouse_sensitivity / view_zoom
|
||||||
head.rotation_degrees.x = clamp(current_tilt, -90, 90)
|
head.rotation_degrees.x = clamp(current_tilt, -90, 90)
|
||||||
|
|
||||||
func _input(event) -> void:
|
func _input(event) -> void:
|
||||||
|
@ -50,6 +69,16 @@ func _input(event) -> void:
|
||||||
else:
|
else:
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("view_zoom"):
|
||||||
|
#tween.stop_all()
|
||||||
|
tween.interpolate_property(self, "view_zoom", view_zoom, 4.0, 0.5, Tween.TRANS_SINE, Tween.EASE_IN_OUT)
|
||||||
|
tween.start()
|
||||||
|
|
||||||
|
if Input.is_action_just_released("view_zoom"):
|
||||||
|
#tween.stop_all()
|
||||||
|
tween.interpolate_property(self, "view_zoom", view_zoom, 1.0, 0.25, Tween.TRANS_SINE, Tween.EASE_IN_OUT)
|
||||||
|
tween.start()
|
||||||
|
|
||||||
aim(event)
|
aim(event)
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
|
@ -89,6 +118,37 @@ func _physics_process(delta):
|
||||||
|
|
||||||
slide = move_and_slide_with_snap(movement, snap, Vector3.UP)
|
slide = move_and_slide_with_snap(movement, snap, Vector3.UP)
|
||||||
|
|
||||||
|
# (stair) climbing
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if get_slide_count() > 1:
|
||||||
|
var hit_wall = false
|
||||||
|
for i in range(0, get_slide_count()):
|
||||||
|
if get_slide_collision(i).position.y > global_transform.origin.y:
|
||||||
|
hit_wall = true
|
||||||
|
print("hit a wall!")
|
||||||
|
break
|
||||||
|
|
||||||
|
if not hit_wall:
|
||||||
|
print("didn't hit a wall")
|
||||||
|
else:
|
||||||
|
var climb_test_start = global_transform.translated(Vector3(0, climb_height, 0))
|
||||||
|
var climb_test_step = Vector3(0,0,-0.1).rotated(Vector3.UP, rotation.y)
|
||||||
|
if not test_move(climb_test_start, climb_test_step): # no collision
|
||||||
|
var step = climb_check.get_collision_point().y
|
||||||
|
var start = global_transform.origin.y
|
||||||
|
print("step: ", step, " start: ", start)
|
||||||
|
global_transform.origin.y = step
|
||||||
|
# var climb = start - step
|
||||||
|
# body.shape.height -= climb
|
||||||
|
# body.translation.y += climb / 2
|
||||||
|
#
|
||||||
|
# climb_tween.interpolate_property(body, "shape/height", body.shape.height, body.shape.height + climb, 1, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
||||||
|
# climb_tween.interpolate_property(body, "shape/translation.y", body.translation.y, body.translation.y - (climb / 2), 1, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
||||||
|
# climb_tween.start()
|
||||||
|
|
||||||
|
|
||||||
if not is_on_floor(): # while in mid-air collisions affect momentum
|
if not is_on_floor(): # while in mid-air collisions affect momentum
|
||||||
velocity.x = slide.x
|
velocity.x = slide.x
|
||||||
velocity.z = slide.z
|
velocity.z = slide.z
|
||||||
|
|
|
@ -3,28 +3,28 @@
|
||||||
[ext_resource path="res://Assets/Characters/Player.gd" type="Script" id=1]
|
[ext_resource path="res://Assets/Characters/Player.gd" type="Script" id=1]
|
||||||
|
|
||||||
[sub_resource type="CapsuleMesh" id=1]
|
[sub_resource type="CapsuleMesh" id=1]
|
||||||
radius = 0.5
|
radius = 0.4
|
||||||
mid_height = 1.3
|
mid_height = 0.9
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape3D" id=2]
|
[sub_resource type="CapsuleShape3D" id=2]
|
||||||
radius = 0.5
|
radius = 0.4
|
||||||
height = 1.3
|
height = 0.9
|
||||||
|
|
||||||
[sub_resource type="CylinderShape3D" id=3]
|
[sub_resource type="CylinderShape3D" id=3]
|
||||||
radius = 0.25
|
radius = 0.25
|
||||||
height = 0.5
|
height = 0.5
|
||||||
|
|
||||||
[node name="Player" type="KinematicBody3D"]
|
[node name="Player" type="KinematicBody3D"]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2, 0 )
|
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="Mesh" type="MeshInstance3D" parent="."]
|
[node name="Mesh" type="MeshInstance3D" parent="."]
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.852763, 0 )
|
||||||
mesh = SubResource( 1 )
|
mesh = SubResource( 1 )
|
||||||
surface_material_override/0 = null
|
surface_material_override/0 = null
|
||||||
script = null
|
script = null
|
||||||
|
|
||||||
[node name="Head" type="Node3D" parent="."]
|
[node name="Head" type="Node3D" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.45276, 0 )
|
||||||
script = null
|
script = null
|
||||||
|
|
||||||
[node name="Camera" type="Camera3D" parent="Head"]
|
[node name="Camera" type="Camera3D" parent="Head"]
|
||||||
|
@ -36,18 +36,30 @@ script = null
|
||||||
[node name="Hand" type="Node3D" parent="Head/Camera"]
|
[node name="Hand" type="Node3D" parent="Head/Camera"]
|
||||||
script = null
|
script = null
|
||||||
|
|
||||||
|
[node name="Tween" type="Tween" parent="Head/Camera"]
|
||||||
|
script = null
|
||||||
|
|
||||||
[node name="Body" type="CollisionShape3D" parent="."]
|
[node name="Body" type="CollisionShape3D" parent="."]
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.852763, 0 )
|
||||||
shape = SubResource( 2 )
|
shape = SubResource( 2 )
|
||||||
script = null
|
script = null
|
||||||
|
|
||||||
[node name="Feet" type="CollisionShape3D" parent="."]
|
[node name="Feet" type="CollisionShape3D" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.9, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.252763, 0 )
|
||||||
shape = SubResource( 3 )
|
shape = SubResource( 3 )
|
||||||
disabled = true
|
disabled = true
|
||||||
script = null
|
script = null
|
||||||
|
|
||||||
[node name="GroundCheck" type="RayCast3D" parent="."]
|
[node name="GroundCheck" type="RayCast3D" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.2, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.952763, 0 )
|
||||||
target_position = Vector3( 0, -1.1, 0 )
|
target_position = Vector3( 0, -1.1, 0 )
|
||||||
debug_shape_thickness = 5.0
|
debug_shape_thickness = 5.0
|
||||||
script = null
|
script = null
|
||||||
|
|
||||||
|
[node name="ClimbCheck" type="RayCast3D" parent="."]
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.00905, -0.7 )
|
||||||
|
target_position = Vector3( 0, -2, 0 )
|
||||||
|
script = null
|
||||||
|
|
||||||
|
[node name="ClimbTween" type="Tween" parent="."]
|
||||||
|
script = null
|
||||||
|
|
|
@ -58,7 +58,7 @@ trigger_secondary={
|
||||||
}
|
}
|
||||||
view_zoom={
|
view_zoom={
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":16777240,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":90,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
move_special={
|
move_special={
|
||||||
|
|
Reference in New Issue