Basic character controller
This commit is contained in:
parent
b7a3f1a7b2
commit
4de70a539b
7
Materials/Dark_ProtoMat.tres
Normal file
7
Materials/Dark_ProtoMat.tres
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[gd_resource type="SpatialMaterial" load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Textures/kenney_prototype_textures/dark/texture_01.png" type="Texture" id=1]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
albedo_texture = ExtResource( 1 )
|
||||||
|
uv1_triplanar = true
|
7
Materials/Orange_ProtoMat.tres
Normal file
7
Materials/Orange_ProtoMat.tres
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[gd_resource type="SpatialMaterial" load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Textures/kenney_prototype_textures/orange/texture_01.png" type="Texture" id=1]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
albedo_texture = ExtResource( 1 )
|
||||||
|
uv1_triplanar = true
|
54
Player.gd
54
Player.gd
@ -1,8 +1,20 @@
|
|||||||
extends KinematicBody
|
extends KinematicBody
|
||||||
|
|
||||||
var mouse_sensitivity = 0.03
|
export var speed = 20
|
||||||
|
export var h_acceleration = 6
|
||||||
|
export var gravity = 40
|
||||||
|
export var jump = 30
|
||||||
|
|
||||||
|
export var mouse_sensitivity = 0.03
|
||||||
|
|
||||||
|
var full_contact = false
|
||||||
|
var direction = Vector3()
|
||||||
|
var h_velocity = Vector3()
|
||||||
|
var movement = Vector3()
|
||||||
|
var gravity_vec = Vector3()
|
||||||
|
|
||||||
onready var head = $Head
|
onready var head = $Head
|
||||||
|
onready var ground_check = $GroundCheck
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
@ -12,3 +24,43 @@ func _input(event):
|
|||||||
rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
|
rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
|
||||||
head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
|
head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
|
||||||
head.rotation.x = clamp(head.rotation.x, deg2rad(-89), deg2rad(89))
|
head.rotation.x = clamp(head.rotation.x, deg2rad(-89), deg2rad(89))
|
||||||
|
|
||||||
|
|
||||||
|
func _physics_process(delta):
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("uncapture_mouse"):
|
||||||
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||||
|
elif Input.is_action_just_released("uncapture_mouse"):
|
||||||
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
|
|
||||||
|
direction = Vector3()
|
||||||
|
|
||||||
|
full_contact = ground_check.is_colliding()
|
||||||
|
|
||||||
|
if not is_on_floor():
|
||||||
|
gravity_vec += Vector3.DOWN * gravity * delta
|
||||||
|
elif is_on_floor() and full_contact:
|
||||||
|
gravity_vec = -get_floor_normal() * gravity
|
||||||
|
else:
|
||||||
|
gravity_vec = -get_floor_normal()
|
||||||
|
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("jump") and (is_on_floor() or ground_check.is_colliding()):
|
||||||
|
gravity_vec = Vector3.UP * jump
|
||||||
|
|
||||||
|
if Input.is_action_pressed("move_forward"):
|
||||||
|
direction -= transform.basis.z
|
||||||
|
elif Input.is_action_pressed("move_backward"):
|
||||||
|
direction += transform.basis.z
|
||||||
|
if Input.is_action_pressed("move_left"):
|
||||||
|
direction -= transform.basis.x
|
||||||
|
elif Input.is_action_pressed("move_right"):
|
||||||
|
direction += transform.basis.x
|
||||||
|
|
||||||
|
direction = direction.normalized()
|
||||||
|
h_velocity = h_velocity.linear_interpolate(direction * speed, h_acceleration * delta)
|
||||||
|
movement.z = h_velocity.z + gravity_vec.z
|
||||||
|
movement.x = h_velocity.x + gravity_vec.x
|
||||||
|
movement.y = gravity_vec.y
|
||||||
|
|
||||||
|
move_and_slide(movement, Vector3.UP)
|
||||||
|
@ -29,3 +29,8 @@ shape = SubResource( 3 )
|
|||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.84218, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.84218, 0 )
|
||||||
|
|
||||||
[node name="Camera" type="Camera" parent="Head"]
|
[node name="Camera" type="Camera" parent="Head"]
|
||||||
|
|
||||||
|
[node name="GroundCheck" type="RayCast" parent="."]
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0 )
|
||||||
|
enabled = true
|
||||||
|
cast_to = Vector3( 0, -1.5, 0 )
|
||||||
|
@ -1,23 +1,27 @@
|
|||||||
[gd_scene load_steps=4 format=2]
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Textures/kenney_prototype_textures/dark/texture_01.png" type="Texture" id=1]
|
[ext_resource path="res://Materials/Dark_ProtoMat.tres" type="Material" id=1]
|
||||||
[ext_resource path="res://Player.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://Player.tscn" type="PackedScene" id=2]
|
||||||
|
[ext_resource path="res://Materials/Orange_ProtoMat.tres" type="Material" id=3]
|
||||||
[sub_resource type="SpatialMaterial" id=1]
|
|
||||||
albedo_texture = ExtResource( 1 )
|
|
||||||
uv1_triplanar = true
|
|
||||||
|
|
||||||
[node name="Spatial" type="Spatial"]
|
[node name="Spatial" type="Spatial"]
|
||||||
|
|
||||||
[node name="CSGCombiner" type="CSGCombiner" parent="."]
|
[node name="CSGCombiner" type="CSGCombiner" parent="."]
|
||||||
|
use_collision = true
|
||||||
|
|
||||||
[node name="CSGBox" type="CSGBox" parent="CSGCombiner"]
|
[node name="CSGBox" type="CSGBox" parent="CSGCombiner"]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -4, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0 )
|
||||||
width = 26.0
|
width = 106.0
|
||||||
depth = 26.0
|
depth = 82.0
|
||||||
material = SubResource( 1 )
|
material = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="CSGPolygon" type="CSGPolygon" parent="CSGCombiner"]
|
||||||
|
transform = Transform( 3.51681, 0, 0, 0, 4.16599, 0, 0, 0, 14.5504, 22.4026, 0, 7 )
|
||||||
|
polygon = PoolVector2Array( 0, 0, -3, 0, 1, 1, 1, 0 )
|
||||||
|
material = ExtResource( 3 )
|
||||||
|
|
||||||
[node name="DirectionalLight" type="DirectionalLight" parent="."]
|
[node name="DirectionalLight" type="DirectionalLight" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 0.258819, 0.965926, 0, -0.965926, 0.258819, 0, 15.4487, 13 )
|
transform = Transform( 1, 0, 0, 0, 0.258819, 0.965926, 0, -0.965926, 0.258819, 0, 15.4487, 13 )
|
||||||
|
|
||||||
[node name="Player" parent="." instance=ExtResource( 2 )]
|
[node name="Player" parent="." instance=ExtResource( 2 )]
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 9, 0 )
|
||||||
|
@ -2,28 +2,30 @@
|
|||||||
|
|
||||||
importer="texture"
|
importer="texture"
|
||||||
type="StreamTexture"
|
type="StreamTexture"
|
||||||
path="res://.import/texture_01.png-7bf1c5b580a4e5291a946c3b0f1b0019.stex"
|
path.s3tc="res://.import/texture_01.png-7bf1c5b580a4e5291a946c3b0f1b0019.s3tc.stex"
|
||||||
|
path.etc2="res://.import/texture_01.png-7bf1c5b580a4e5291a946c3b0f1b0019.etc2.stex"
|
||||||
metadata={
|
metadata={
|
||||||
"vram_texture": false
|
"imported_formats": [ "s3tc", "etc2" ],
|
||||||
|
"vram_texture": true
|
||||||
}
|
}
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
|
|
||||||
source_file="res://Textures/kenney_prototype_textures/orange/texture_01.png"
|
source_file="res://Textures/kenney_prototype_textures/orange/texture_01.png"
|
||||||
dest_files=[ "res://.import/texture_01.png-7bf1c5b580a4e5291a946c3b0f1b0019.stex" ]
|
dest_files=[ "res://.import/texture_01.png-7bf1c5b580a4e5291a946c3b0f1b0019.s3tc.stex", "res://.import/texture_01.png-7bf1c5b580a4e5291a946c3b0f1b0019.etc2.stex" ]
|
||||||
|
|
||||||
[params]
|
[params]
|
||||||
|
|
||||||
compress/mode=0
|
compress/mode=2
|
||||||
compress/lossy_quality=0.7
|
compress/lossy_quality=0.7
|
||||||
compress/hdr_mode=0
|
compress/hdr_mode=0
|
||||||
compress/bptc_ldr=0
|
compress/bptc_ldr=0
|
||||||
compress/normal_map=0
|
compress/normal_map=0
|
||||||
flags/repeat=0
|
flags/repeat=true
|
||||||
flags/filter=true
|
flags/filter=true
|
||||||
flags/mipmaps=false
|
flags/mipmaps=true
|
||||||
flags/anisotropic=false
|
flags/anisotropic=false
|
||||||
flags/srgb=2
|
flags/srgb=1
|
||||||
process/fix_alpha_border=true
|
process/fix_alpha_border=true
|
||||||
process/premult_alpha=false
|
process/premult_alpha=false
|
||||||
process/HDR_as_SRGB=false
|
process/HDR_as_SRGB=false
|
||||||
@ -31,5 +33,5 @@ process/invert_color=false
|
|||||||
process/normal_map_invert_y=false
|
process/normal_map_invert_y=false
|
||||||
stream=false
|
stream=false
|
||||||
size_limit=0
|
size_limit=0
|
||||||
detect_3d=true
|
detect_3d=false
|
||||||
svg/scale=1.0
|
svg/scale=1.0
|
||||||
|
@ -18,6 +18,39 @@ config/icon="res://icon.png"
|
|||||||
|
|
||||||
common/drop_mouse_on_gui_input_disabled=true
|
common/drop_mouse_on_gui_input_disabled=true
|
||||||
|
|
||||||
|
[input]
|
||||||
|
|
||||||
|
move_forward={
|
||||||
|
"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,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
move_backward={
|
||||||
|
"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,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
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,"physical_scancode":0,"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,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
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,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
uncapture_mouse={
|
||||||
|
"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":16777240,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[physics]
|
[physics]
|
||||||
|
|
||||||
common/enable_pause_aware_picking=true
|
common/enable_pause_aware_picking=true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user