Added basic movement to Player
parent
4406c2e0d4
commit
24552a6cfc
|
@ -0,0 +1,94 @@
|
|||
extends KinematicBody3D
|
||||
|
||||
@export var mouse_sensitivity := 0.35
|
||||
@export var move_speed := 15
|
||||
|
||||
@onready var head = $Head
|
||||
@onready var ground_check = $GroundCheck
|
||||
|
||||
|
||||
var move_direction := Vector3.ZERO
|
||||
var accel_h := 12
|
||||
var accel_air := 1
|
||||
var accel_ground := 12
|
||||
var gravity := 28
|
||||
var jump := 14
|
||||
|
||||
var vel_h := Vector3.ZERO
|
||||
var movement := Vector3.ZERO
|
||||
var gravity_vec := Vector3.ZERO
|
||||
var ground_contact := false
|
||||
var slide := Vector3.ZERO
|
||||
|
||||
func _ready() -> void:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
func aim(event) -> void:
|
||||
var mouse_motion = event as InputEventMouseMotion
|
||||
|
||||
if mouse_motion:
|
||||
rotation_degrees.y -= mouse_motion.relative.x * mouse_sensitivity
|
||||
|
||||
var current_tilt: float = head.rotation_degrees.x
|
||||
current_tilt -= mouse_motion.relative.y * mouse_sensitivity
|
||||
head.rotation_degrees.x = clamp(current_tilt, -90, 90)
|
||||
|
||||
func _input(event) -> void:
|
||||
|
||||
if Input.is_action_just_pressed("ui_cancel"):
|
||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
else:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
aim(event)
|
||||
|
||||
func _physics_process(delta):
|
||||
move_direction = Vector3.ZERO
|
||||
|
||||
if ground_check.is_colliding():
|
||||
ground_contact = true
|
||||
else:
|
||||
ground_contact = false
|
||||
|
||||
if not is_on_floor():
|
||||
gravity_vec += Vector3.DOWN * gravity * delta
|
||||
accel_h = accel_air
|
||||
print("AIR")
|
||||
elif is_on_floor() and ground_contact:
|
||||
accel_h = accel_ground
|
||||
print("FLOOR")
|
||||
gravity_vec = -get_floor_normal() * gravity
|
||||
else:
|
||||
print("OTHER")
|
||||
accel_h = accel_ground
|
||||
#gravity_vec = -get_floor_normal()
|
||||
gravity_vec = Vector3.DOWN * gravity * delta
|
||||
|
||||
if Input.is_action_just_pressed("move_jump") and (is_on_floor() or ground_contact):
|
||||
gravity_vec = Vector3.UP * jump
|
||||
|
||||
if Input.is_action_pressed("move_forward"):
|
||||
move_direction -= transform.basis.z
|
||||
if Input.is_action_pressed("move_backward"):
|
||||
move_direction += transform.basis.z
|
||||
if Input.is_action_pressed("move_left"):
|
||||
move_direction -= transform.basis.x
|
||||
if Input.is_action_pressed("move_right"):
|
||||
move_direction += transform.basis.x
|
||||
|
||||
if move_direction.length() > 0: # normalized() will return a null
|
||||
move_direction = move_direction.normalized()
|
||||
|
||||
vel_h = vel_h.lerp(move_direction * move_speed, accel_h * delta)
|
||||
|
||||
movement.z = vel_h.z + gravity_vec.z
|
||||
movement.x = vel_h.x + gravity_vec.x
|
||||
movement.y = gravity_vec.y
|
||||
|
||||
slide = move_and_slide(movement, Vector3.UP, )
|
||||
|
||||
if not is_on_floor():
|
||||
vel_h.x = slide.x
|
||||
vel_h.z = slide.z
|
||||
gravity_vec.y = slide.y
|
|
@ -0,0 +1,47 @@
|
|||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://Classes/Player.gd" type="Script" id=1]
|
||||
|
||||
[sub_resource type="CapsuleMesh" id=1]
|
||||
radius = 0.5
|
||||
mid_height = 1.3
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id=2]
|
||||
radius = 0.5
|
||||
height = 1.3
|
||||
|
||||
[sub_resource type="CylinderShape3D" id=3]
|
||||
radius = 0.25
|
||||
height = 0.5
|
||||
|
||||
[node name="Player" type="KinematicBody3D"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0 )
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Mesh" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource( 1 )
|
||||
surface_material_override/0 = null
|
||||
script = null
|
||||
|
||||
[node name="Head" type="Node3D" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
|
||||
script = null
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="Head"]
|
||||
transform = Transform( 1, 0, 2.38419e-07, 0, 1, 0, -2.38419e-07, 0, 1, 0, 0, 0 )
|
||||
current = true
|
||||
fov = 90.0
|
||||
script = null
|
||||
|
||||
[node name="Body" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource( 2 )
|
||||
script = null
|
||||
|
||||
[node name="Feet" type="CollisionShape3D" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.9, 0 )
|
||||
shape = SubResource( 3 )
|
||||
script = null
|
||||
|
||||
[node name="GroundCheck" type="RayCast3D" parent="."]
|
||||
target_position = Vector3( 0, -1.5, 0 )
|
||||
script = null
|
File diff suppressed because one or more lines are too long
|
@ -1,16 +0,0 @@
|
|||
extends KinematicBody3D
|
||||
|
||||
@export var _mouse_sensitivity := 0.35
|
||||
|
||||
func _ready() -> void:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
func _input(event) -> void:
|
||||
var mouse_motion = event as InputEventMouseMotion
|
||||
|
||||
if mouse_motion:
|
||||
rotation_degrees.y -= mouse_motion.relative.x * _mouse_sensitivity
|
||||
|
||||
var current_tilt: float = $Head.rotation_degrees.x
|
||||
current_tilt -= mouse_motion.relative.y * _mouse_sensitivity
|
||||
$Head.rotation_degrees.x = clamp(current_tilt, -90, 90)
|
|
@ -16,71 +16,88 @@ config/icon="res://icon.png"
|
|||
|
||||
[input]
|
||||
|
||||
player_forward={
|
||||
move_forward={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt":false,"shift":false,"meta":false,"command":false,"pressed":false,"keycode":87,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_backward={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt":false,"shift":false,"meta":false,"command":false,"pressed":false,"keycode":83,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_left={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt":false,"shift":false,"meta":false,"command":false,"pressed":false,"keycode":65,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_right={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt":false,"shift":false,"meta":false,"command":false,"pressed":false,"keycode":68,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_jump={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt":false,"shift":false,"meta":false,"command":false,"pressed":false,"keycode":32,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_crouch={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt":false,"shift":false,"meta":false,"command":false,"pressed":false,"keycode":16777238,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
trigger_primary={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt":false,"shift":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
trigger_secondary={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt":false,"shift":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":2,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
view_zoom={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt":false,"shift":false,"meta":false,"command":false,"pressed":false,"keycode":16777240,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_special={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt":false,"shift":false,"meta":false,"command":false,"pressed":false,"keycode":16777237,"physical_keycode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
weapon_previous={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
player_backward={
|
||||
weapon_next={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
player_left={
|
||||
weapon_reload={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
player_right={
|
||||
weapon_swap={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
player_jump={
|
||||
weapon_1={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
player_crouch={
|
||||
weapon_2={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
player_trigger_primary={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
player_trigger_secondary={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
player_zoom={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
player_jetpack={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
player_weapon_previous={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
player_weapon_next={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
player_weapon_reload={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
player_weapon_swap={
|
||||
weapon_3={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
shadows/directional_shadow/soft_shadow_quality=4
|
||||
shadows/shadows/soft_shadow_quality=4
|
||||
global_illumination/sdfgi/probe_ray_count=2
|
||||
global_illumination/sdfgi/frames_to_converge=0
|
||||
global_illumination/sdfgi/frames_to_update_lights=4
|
||||
anti_aliasing/quality/msaa=1
|
||||
anti_aliasing/quality/screen_space_aa=1
|
||||
anti_aliasing/quality/use_debanding=true
|
||||
environment/defaults/default_environment="res://default_env.tres"
|
||||
|
|
Reference in New Issue