- added basic movement and camera control

- collsion with floor does not work!
This commit is contained in:
incredibleLeitman 2019-11-02 19:02:16 +01:00
parent b88d68d27b
commit f280e6e349
4 changed files with 147 additions and 18 deletions

View File

@ -7,6 +7,12 @@
[node name="Player" type="KinematicBody"] [node name="Player" type="KinematicBody"]
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="Body" type="Spatial" parent="."]
[node name="Camera" type="Camera" parent="Body"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
current = true
[node name="Collider" type="CollisionShape" parent="."] [node name="Collider" type="CollisionShape" 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, 0 )
shape = SubResource( 1 ) shape = SubResource( 1 )

View File

@ -1,13 +1,89 @@
extends KinematicBody extends KinematicBody
# Declare member variables here. Examples: # export variable
# var a = 2
# var b = "text" # const
const GRAVITY = -24.8
const JUMP_SPEED = 18
const MOVE_SPEED = 20
const SPRINT_SPEED = 40
const ACCEL = 4.5
const MAX_SLOPE_ANGLE = 40
const MOUSE_SENSITIVITY = 0.05
# private members
var _body
var _camera
var _dir = Vector3();
var _vel = Vector3();
var _is_sprinting;
# Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
pass # Replace with function body. _body = $Body
_camera = $Body/Camera
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _physics_process(delta):
process_input(delta)
process_movement(delta)
func process_input(delta):
# Walking
var input_movement_vector = Vector2()
if Input.is_action_pressed("move_fwrd"):
input_movement_vector.y += 1
if Input.is_action_pressed("move_back"):
input_movement_vector.y -= 1
if Input.is_action_pressed("move_left"):
input_movement_vector.x -= 1
if Input.is_action_pressed("move_right"):
input_movement_vector.x += 1
# look around with mouse
_dir = Vector3()
var camera_transform = _camera.get_global_transform()
_dir += -camera_transform.basis.z * input_movement_vector.y
_dir += camera_transform.basis.x * input_movement_vector.x
# jumping
# TODO: remove after collision is working
if Input.is_action_just_pressed("move_jump"): # and is_on_floor():
_vel.y = JUMP_SPEED
# sprinting
_is_sprinting = Input.is_action_pressed("move_sprint")
func process_movement(delta):
_vel.y += delta * GRAVITY
# quickfix because collision is not working yet:
if _vel.y < 0:
_vel.y = 0
# set movement speed
var target = _dir
if _is_sprinting:
target *= SPRINT_SPEED
else:
target *= MOVE_SPEED
var hvel = _vel
hvel = hvel.linear_interpolate(target, ACCEL * delta)
_vel.x = hvel.x
_vel.z = hvel.z
_vel = move_and_slide(_vel, Vector3(0, 1, 0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
func _input(event):
# capture mouse movement
if event is InputEventMouseMotion:
_body.rotate_x(deg2rad(event.relative.y * MOUSE_SENSITIVITY * -1))
self.rotate_y(deg2rad(event.relative.x * MOUSE_SENSITIVITY * -1))
var camera_rot = _body.rotation_degrees
camera_rot.x = clamp(camera_rot.x, -70, 70)
_body.rotation_degrees = camera_rot
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=9 format=2] [gd_scene load_steps=11 format=2]
[ext_resource path="res://Characters/Util/PathNavigatorForKinematicBody.tscn" type="PackedScene" id=1] [ext_resource path="res://Characters/Player/Player.tscn" type="PackedScene" id=1]
[ext_resource path="res://Characters/Meldewesen/Meldewesen.tscn" type="PackedScene" id=2] [ext_resource path="res://Characters/Util/PathNavigatorForKinematicBody.tscn" type="PackedScene" id=2]
[ext_resource path="res://Util/NodeGroupNotifier.tscn" type="PackedScene" id=3] [ext_resource path="res://Characters/Meldewesen/Meldewesen.tscn" type="PackedScene" id=3]
[ext_resource path="res://Util/NodeGroupNotifier.tscn" type="PackedScene" id=4]
[sub_resource type="NavigationMesh" id=1] [sub_resource type="NavigationMesh" id=1]
vertices = PoolVector3Array( -1.3, 0.4, -1.6, 0.200001, 0.4, -1.6, 0.200001, 0.4, -9.4, -9.4, 0.4, -0.0999994, -1.6, 0.4, -0.0999994, -1.3, 0.4, -1.6, 0.200001, 0.4, -9.4, -9.4, 0.4, -9.4, 0.200001, 0.4, -9.4, 0.200001, 0.4, -1.6, 1.4, 0.4, -1.6, 1.4, 0.4, -1.6, 1.7, 0.4, -0.0999994, 9.5, 0.4, -0.0999994, 9.5, 0.4, -9.4, 0.200001, 0.4, -9.4, 0.200001, 0.4, 9.5, 0.200001, 0.4, 8.3, -1.6, 0.4, 8, -9.4, 0.4, 9.5, -1.6, 0.4, 5, 0.200001, 0.4, 4.7, 0.200001, 0.4, 1.7, -1.6, 0.4, 1.4, -1.6, 0.4, 5, -1.6, 0.4, 1.4, -9.4, 0.4, -0.0999994, -9.4, 0.4, 9.5, -1.6, 0.4, 1.4, -1.6, 0.4, -0.0999994, -9.4, 0.4, -0.0999994, -9.4, 0.4, 9.5, -1.6, 0.4, 8, -1.6, 0.4, 5, 1.7, 0.4, 8, 0.200001, 0.4, 8.3, 0.200001, 0.4, 9.5, 9.5, 0.4, 9.5, 0.200001, 0.4, 1.7, 0.200001, 0.4, 4.7, 1.7, 0.4, 5, 1.7, 0.4, 1.4, 1.7, 0.4, 5, 9.5, 0.4, 9.5, 9.5, 0.4, -0.0999994, 1.7, 0.4, 1.4, 1.7, 0.4, 5, 1.7, 0.4, 8, 9.5, 0.4, 9.5, 9.5, 0.4, -0.0999994, 1.7, 0.4, -0.0999994, 1.7, 0.4, 1.4 ) vertices = PoolVector3Array( -1.3, 0.4, -1.6, 0.200001, 0.4, -1.6, 0.200001, 0.4, -9.4, -9.4, 0.4, -0.0999994, -1.6, 0.4, -0.0999994, -1.3, 0.4, -1.6, 0.200001, 0.4, -9.4, -9.4, 0.4, -9.4, 0.200001, 0.4, -9.4, 0.200001, 0.4, -1.6, 1.4, 0.4, -1.6, 1.4, 0.4, -1.6, 1.7, 0.4, -0.0999994, 9.5, 0.4, -0.0999994, 9.5, 0.4, -9.4, 0.200001, 0.4, -9.4, 0.200001, 0.4, 9.5, 0.200001, 0.4, 8.3, -1.6, 0.4, 8, -9.4, 0.4, 9.5, -1.6, 0.4, 5, 0.200001, 0.4, 4.7, 0.200001, 0.4, 1.7, -1.6, 0.4, 1.4, -1.6, 0.4, 5, -1.6, 0.4, 1.4, -9.4, 0.4, -0.0999994, -9.4, 0.4, 9.5, -1.6, 0.4, 1.4, -1.6, 0.4, -0.0999994, -9.4, 0.4, -0.0999994, -9.4, 0.4, 9.5, -1.6, 0.4, 8, -1.6, 0.4, 5, 1.7, 0.4, 8, 0.200001, 0.4, 8.3, 0.200001, 0.4, 9.5, 9.5, 0.4, 9.5, 0.200001, 0.4, 1.7, 0.200001, 0.4, 4.7, 1.7, 0.4, 5, 1.7, 0.4, 1.4, 1.7, 0.4, 5, 9.5, 0.4, 9.5, 9.5, 0.4, -0.0999994, 1.7, 0.4, 1.4, 1.7, 0.4, 5, 1.7, 0.4, 8, 9.5, 0.4, 9.5, 9.5, 0.4, -0.0999994, 1.7, 0.4, -0.0999994, 1.7, 0.4, 1.4 )
@ -13,15 +14,17 @@ polygons = [ PoolIntArray( 2, 0, 1 ), PoolIntArray( 7, 3, 6 ), PoolIntArray( 3,
[sub_resource type="PlaneMesh" id=3] [sub_resource type="PlaneMesh" id=3]
size = Vector2( 20, 20 ) size = Vector2( 20, 20 )
[sub_resource type="BoxShape" id=6]
extents = Vector3( 10, 1, 10 )
[sub_resource type="SphereShape" id=4] [sub_resource type="SphereShape" id=4]
[sub_resource type="SphereMesh" id=5] [sub_resource type="SphereMesh" id=5]
[node name="Navigation" type="Navigation"] [node name="Navigation" type="Navigation"]
[node name="Camera" type="Camera" parent="."] [node name="Player" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 0.866025, 0.5, 0, -0.5, 0.866025, 0, 10, 16 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.634059, -0.437212, 8.83401 )
current = true
[node name="DirectionalLight" type="DirectionalLight" parent="."] [node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 0.766044, -0.582564, 0.271654, 0, 0.422618, 0.906308, -0.642788, -0.694272, 0.323744, 0, 5, 0 ) transform = Transform( 0.766044, -0.582564, 0.271654, 0, 0.422618, 0.906308, -0.642788, -0.694272, 0.323744, 0, 5, 0 )
@ -43,12 +46,19 @@ material/0 = null
mesh = SubResource( 3 ) mesh = SubResource( 3 )
material/0 = null material/0 = null
[node name="PathNavigatorForKinematicBody" parent="." instance=ExtResource( 1 )] [node name="Area" type="Area" parent="NavigationMeshInstance"]
[node name="CollisionShape" type="CollisionShape" parent="NavigationMeshInstance/Area"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
shape = SubResource( 6 )
[node name="PathNavigatorForKinematicBody" parent="." instance=ExtResource( 2 )]
editor/display_folded = true
body_nodepath = NodePath("Meldewesen") body_nodepath = NodePath("Meldewesen")
[node name="Meldewesen" parent="PathNavigatorForKinematicBody" instance=ExtResource( 2 )] [node name="Meldewesen" parent="PathNavigatorForKinematicBody" instance=ExtResource( 3 )]
[node name="NodeGroupNotifier" parent="." instance=ExtResource( 3 )] [node name="NodeGroupNotifier" parent="." instance=ExtResource( 4 )]
group_name = "Navigator" group_name = "Navigator"
node_to_send = NodePath("..") node_to_send = NodePath("..")

View File

@ -19,6 +19,43 @@ config/name="retrace"
run/main_scene="res://Level/PathTestWorld.tscn" run/main_scene="res://Level/PathTestWorld.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[input]
move_left={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
]
}
move_right={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
]
}
move_fwrd={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
]
}
move_back={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
]
}
move_jump={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null)
]
}
move_sprint={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777237,"unicode":0,"echo":false,"script":null)
]
}
[layer_names] [layer_names]
3d_render/layer_1="Masked" 3d_render/layer_1="Masked"