first commit
This commit is contained in:
commit
e1af866014
|
@ -0,0 +1,2 @@
|
||||||
|
# Normalize EOL for all files that Git considers text files.
|
||||||
|
* text=auto eol=lf
|
|
@ -0,0 +1,2 @@
|
||||||
|
# Godot 4+ specific ignores
|
||||||
|
.godot/
|
|
@ -0,0 +1,24 @@
|
||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
distribute this software, either in source code form or as a compiled
|
||||||
|
binary, for any purpose, commercial or non-commercial, and by any
|
||||||
|
means.
|
||||||
|
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors
|
||||||
|
of this software dedicate any and all copyright interest in the
|
||||||
|
software to the public domain. We make this dedication for the benefit
|
||||||
|
of the public at large and to the detriment of our heirs and
|
||||||
|
successors. We intend this dedication to be an overt act of
|
||||||
|
relinquishment in perpetuity of all present and future rights to this
|
||||||
|
software under copyright law.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
For more information, please refer to <https://unlicense.org>
|
|
@ -0,0 +1,20 @@
|
||||||
|
![](https://github.com/sammburr/Basic-FPS-Player-GODOT-4.0/blob/4929a04b2791b13184eea82ead9caaf57894be48/addons/Basic%20FPS%20Player/Assets/Basic%20FPS%20Player.png)
|
||||||
|
|
||||||
|
# Basic-FPS-Player-GODOT-4.0
|
||||||
|
(`GDScript`) Godot 4.0 *very* basic FPS player controller with mouse and keyboard input for a kick start in your fps project.
|
||||||
|
Current version **V1.2**
|
||||||
|
- Basic walk + jump
|
||||||
|
- Head bob
|
||||||
|
- Mouse acceleration + smoothing
|
||||||
|
- Easy action rebinding
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
See: [Youtube Installation Video](https://www.youtube.com/watch?v=-yS7S-bYY3s)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
All relevant settings are exported to godot to tweak within the editor.
|
||||||
|
|
||||||
|
The character will only listen to mouse input when the mouse is captured;
|
||||||
|
(`Input.mouse_mode = Input.MOUSE_MODE_CAPTURED`).
|
||||||
|
|
||||||
|
Enjoy! :)
|
Binary file not shown.
After Width: | Height: | Size: 8.3 KiB |
|
@ -0,0 +1,34 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://dauwq2ms3546s"
|
||||||
|
path="res://.godot/imported/Basic FPS Player.png-0760118432058d9ff43f455711584e15.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://addons/Basic FPS Player/Assets/Basic FPS Player.png"
|
||||||
|
dest_files=["res://.godot/imported/Basic FPS Player.png-0760118432058d9ff43f455711584e15.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
width="15.999999"
|
||||||
|
height="16"
|
||||||
|
viewBox="0 0 4.233333 4.2333332"
|
||||||
|
version="1.1"
|
||||||
|
id="svg1"
|
||||||
|
xml:space="preserve"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
|
||||||
|
id="namedview1"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#000000"
|
||||||
|
borderopacity="0.25"
|
||||||
|
inkscape:showpageshadow="2"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:deskcolor="#d1d1d1"
|
||||||
|
inkscape:document-units="mm" /><defs
|
||||||
|
id="defs1"><linearGradient
|
||||||
|
id="linearGradient5"
|
||||||
|
inkscape:collect="always"><stop
|
||||||
|
style="stop-color:#e50000;stop-opacity:1;"
|
||||||
|
offset="0"
|
||||||
|
id="stop5" /><stop
|
||||||
|
style="stop-color:#e1ff16;stop-opacity:1;"
|
||||||
|
offset="0.39249212"
|
||||||
|
id="stop8" /><stop
|
||||||
|
style="stop-color:#3fe83f;stop-opacity:1;"
|
||||||
|
offset="0.51999998"
|
||||||
|
id="stop7" /><stop
|
||||||
|
style="stop-color:#0ee1ff;stop-opacity:1;"
|
||||||
|
offset="0.64012617"
|
||||||
|
id="stop9" /><stop
|
||||||
|
style="stop-color:#3500f4;stop-opacity:1;"
|
||||||
|
offset="1"
|
||||||
|
id="stop6" /></linearGradient><linearGradient
|
||||||
|
inkscape:collect="always"
|
||||||
|
xlink:href="#linearGradient5"
|
||||||
|
id="linearGradient6"
|
||||||
|
x1="0.36938077"
|
||||||
|
y1="2.1205316"
|
||||||
|
x2="3.8146021"
|
||||||
|
y2="2.1205316"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
spreadMethod="pad" /></defs><g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"><path
|
||||||
|
d="M 1.6923697,0.26844112 A 0.26458333,0.26458333 0 0 0 1.4277864,0.53302446 V 1.3267745 A 0.26458333,0.26458333 0 0 0 1.6923697,1.5913578 H 1.956953 V 1.8532953 A 0.26458333,0.26458333 0 0 0 1.873345,1.8696993 L 1.3306843,2.0506745 1.1497093,1.508014 A 0.26460203,0.26460203 0 0 0 0.64753016,1.6749661 l 0.26458333,0.79375 A 0.26458333,0.26458333 0 0 0 1.2468114,2.6361974 L 1.6923697,2.4880307 v 0.1613958 c 0,0.010848 0.00503,0.020108 0.00635,0.030692 l -1.21152704,0.807508 a 0.26461629,0.26461629 0 1 0 0.2936875,0.4402667 L 2.1186135,3.0362474 2.5141655,3.8262932 A 0.26458333,0.26458333 0 0 0 2.8343114,3.959114 l 0.79375,-0.2645833 A 0.26458333,0.26458333 0 1 0 3.4608447,3.1926161 L 2.8845822,3.384439 2.6266135,2.868237 A 0.25955625,0.25955625 0 0 0 2.750703,2.6494265 V 2.3851078 H 3.1166218 L 3.307651,2.7682245 A 0.26475278,0.26475278 0 1 0 3.7812551,2.5314224 L 3.5166718,2.0022557 A 0.26458333,0.26458333 0 0 0 3.2798697,1.8559411 h -0.79375 V 1.5913578 H 2.750703 A 0.26458333,0.26458333 0 0 0 3.0152864,1.3267745 V 0.53302446 A 0.26458333,0.26458333 0 0 0 2.750703,0.26844112 Z m 0,0.52916667 H 1.956953 V 1.3267745 H 1.6923697 Z"
|
||||||
|
fill="#fc7f7f"
|
||||||
|
id="path1"
|
||||||
|
style="opacity:1;fill:url(#linearGradient6);fill-opacity:1;stroke:none;stroke-width:0.264583;stroke-opacity:1" /></g></svg>
|
After Width: | Height: | Size: 3.1 KiB |
|
@ -0,0 +1,37 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://5dwxsqld3ba4"
|
||||||
|
path="res://.godot/imported/Basic FPS Player.svg-7aa416bb7e9c2ce2ef5be30e3af14df1.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://addons/Basic FPS Player/Assets/Basic FPS Player.svg"
|
||||||
|
dest_files=["res://.godot/imported/Basic FPS Player.svg-7aa416bb7e9c2ce2ef5be30e3af14df1.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
|
svg/scale=1.0
|
||||||
|
editor/scale_with_editor_scale=false
|
||||||
|
editor/convert_colors_with_editor_theme=false
|
|
@ -0,0 +1,70 @@
|
||||||
|
[gd_scene load_steps=12 format=3 uid="uid://vupfism0y8ub"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://addons/Basic FPS Player/basic_player_startup.gd" id="1_fpauf"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://kmyakts4l64t" path="res://addons/Basic FPS Player/basic_player_head.tscn" id="2_uri1i"]
|
||||||
|
|
||||||
|
[sub_resource type="BoxShape3D" id="BoxShape3D_caja7"]
|
||||||
|
size = Vector3(50, 0, 50)
|
||||||
|
|
||||||
|
[sub_resource type="PlaneMesh" id="PlaneMesh_6b5j0"]
|
||||||
|
size = Vector2(50, 50)
|
||||||
|
|
||||||
|
[sub_resource type="BoxMesh" id="BoxMesh_i1cfu"]
|
||||||
|
|
||||||
|
[sub_resource type="Gradient" id="Gradient_t6m8x"]
|
||||||
|
|
||||||
|
[sub_resource type="GradientTexture2D" id="GradientTexture2D_o7yir"]
|
||||||
|
gradient = SubResource("Gradient_t6m8x")
|
||||||
|
fill_from = Vector2(0.401099, 1)
|
||||||
|
fill_to = Vector2(0.450549, 0)
|
||||||
|
|
||||||
|
[sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_msuu0"]
|
||||||
|
panorama = SubResource("GradientTexture2D_o7yir")
|
||||||
|
|
||||||
|
[sub_resource type="Sky" id="Sky_4ggmq"]
|
||||||
|
sky_material = SubResource("PanoramaSkyMaterial_msuu0")
|
||||||
|
|
||||||
|
[sub_resource type="Environment" id="Environment_4mccc"]
|
||||||
|
sky = SubResource("Sky_4ggmq")
|
||||||
|
ambient_light_source = 3
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_li7ud"]
|
||||||
|
|
||||||
|
[node name="main" type="Node3D"]
|
||||||
|
|
||||||
|
[node name="Floor" type="StaticBody3D" parent="."]
|
||||||
|
|
||||||
|
[node name="Collider" type="CollisionShape3D" parent="Floor"]
|
||||||
|
shape = SubResource("BoxShape3D_caja7")
|
||||||
|
|
||||||
|
[node name="Mesh" type="MeshInstance3D" parent="Floor"]
|
||||||
|
mesh = SubResource("PlaneMesh_6b5j0")
|
||||||
|
|
||||||
|
[node name="Cube" type="MeshInstance3D" parent="."]
|
||||||
|
transform = Transform3D(8.608, 5.25034, 0.847749, -5.28845, 8.62094, 0.306904, -0.563037, -0.704172, 10.0782, -12.3987, 6.30559, 0)
|
||||||
|
mesh = SubResource("BoxMesh_i1cfu")
|
||||||
|
|
||||||
|
[node name="Cube2" type="MeshInstance3D" parent="."]
|
||||||
|
transform = Transform3D(2.3394, -7.04204, 6.8789, 0.399539, 7.13256, 7.16585, -9.83616, -1.38514, 1.92713, 9.80706, 5.95309, -16.603)
|
||||||
|
mesh = SubResource("BoxMesh_i1cfu")
|
||||||
|
|
||||||
|
[node name="Cube3" type="MeshInstance3D" parent="."]
|
||||||
|
transform = Transform3D(4.27484, -1.58703, 4.62899, 3.90354, 4.81261, -1.9549, -2.95104, 4.067, 4.11962, 14.8415, 5.95309, 8.53617)
|
||||||
|
mesh = SubResource("BoxMesh_i1cfu")
|
||||||
|
|
||||||
|
[node name="Sun" type="DirectionalLight3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, -0.993258, 0.115925, 0, -0.115925, -0.993258, 1.99157, 9.78125, -4.48814)
|
||||||
|
shadow_enabled = true
|
||||||
|
|
||||||
|
[node name="Enivroment" type="WorldEnvironment" parent="."]
|
||||||
|
environment = SubResource("Environment_4mccc")
|
||||||
|
|
||||||
|
[node name="Basic FPS Player" type="CharacterBody3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0)
|
||||||
|
script = ExtResource("1_fpauf")
|
||||||
|
|
||||||
|
[node name="Head" type="Node3D" parent="Basic FPS Player" instance=ExtResource("2_uri1i")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.412659, 0)
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="Basic FPS Player"]
|
||||||
|
shape = SubResource("CapsuleShape3D_li7ud")
|
|
@ -0,0 +1,5 @@
|
||||||
|
[gd_scene format=3 uid="uid://kmyakts4l64t"]
|
||||||
|
|
||||||
|
[node name="Head" type="Node3D"]
|
||||||
|
|
||||||
|
[node name="Camera3D" type="Camera3D" parent="."]
|
|
@ -0,0 +1,171 @@
|
||||||
|
@tool
|
||||||
|
extends CharacterBody3D
|
||||||
|
|
||||||
|
var BasicFPSPlayerScene : PackedScene = preload("basic_player_head.tscn")
|
||||||
|
var addedHead = false
|
||||||
|
|
||||||
|
func _enter_tree():
|
||||||
|
|
||||||
|
if find_child("Head"):
|
||||||
|
addedHead = true
|
||||||
|
|
||||||
|
if Engine.is_editor_hint() && !addedHead:
|
||||||
|
var s = BasicFPSPlayerScene.instantiate()
|
||||||
|
add_child(s)
|
||||||
|
s.owner = get_tree().edited_scene_root
|
||||||
|
addedHead = true
|
||||||
|
|
||||||
|
## PLAYER MOVMENT SCRIPT ##
|
||||||
|
###########################
|
||||||
|
|
||||||
|
@export_category("Mouse Capture")
|
||||||
|
@export var CAPTURE_ON_START := true
|
||||||
|
|
||||||
|
@export_category("Movement")
|
||||||
|
@export_subgroup("Settings")
|
||||||
|
@export var SPEED := 5.0
|
||||||
|
@export var ACCEL := 50.0
|
||||||
|
@export var IN_AIR_SPEED := 3.0
|
||||||
|
@export var IN_AIR_ACCEL := 5.0
|
||||||
|
@export var JUMP_VELOCITY := 4.5
|
||||||
|
@export_subgroup("Head Bob")
|
||||||
|
@export var HEAD_BOB := true
|
||||||
|
@export var HEAD_BOB_FREQUENCY := 0.3
|
||||||
|
@export var HEAD_BOB_AMPLITUDE := 0.01
|
||||||
|
@export_subgroup("Clamp Head Rotation")
|
||||||
|
@export var CLAMP_HEAD_ROTATION := true
|
||||||
|
@export var CLAMP_HEAD_ROTATION_MIN := -90.0
|
||||||
|
@export var CLAMP_HEAD_ROTATION_MAX := 90.0
|
||||||
|
|
||||||
|
@export_category("Key Binds")
|
||||||
|
@export_subgroup("Mouse")
|
||||||
|
@export var MOUSE_ACCEL := true
|
||||||
|
@export var KEY_BIND_MOUSE_SENS := 0.005
|
||||||
|
@export var KEY_BIND_MOUSE_ACCEL := 50
|
||||||
|
@export_subgroup("Movement")
|
||||||
|
@export var KEY_BIND_UP := "ui_up"
|
||||||
|
@export var KEY_BIND_LEFT := "ui_left"
|
||||||
|
@export var KEY_BIND_RIGHT := "ui_right"
|
||||||
|
@export var KEY_BIND_DOWN := "ui_down"
|
||||||
|
@export var KEY_BIND_JUMP := "ui_accept"
|
||||||
|
|
||||||
|
@export_category("Advanced")
|
||||||
|
@export var UPDATE_PLAYER_ON_PHYS_STEP := true # When check player is moved and rotated in _physics_process (fixed fps)
|
||||||
|
# Otherwise player is updated in _process (uncapped)
|
||||||
|
|
||||||
|
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||||
|
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||||
|
# To keep track of current speed and acceleration
|
||||||
|
var speed = SPEED
|
||||||
|
var accel = ACCEL
|
||||||
|
|
||||||
|
# Used when lerping rotation to reduce stuttering when moving the mouse
|
||||||
|
var rotation_target_player : float
|
||||||
|
var rotation_target_head : float
|
||||||
|
|
||||||
|
# Used when bobing head
|
||||||
|
var head_start_pos : Vector3
|
||||||
|
|
||||||
|
# Current player tick, used in head bob calculation
|
||||||
|
var tick = 0
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
if Engine.is_editor_hint():
|
||||||
|
return
|
||||||
|
|
||||||
|
# Capture mouse if set to true
|
||||||
|
if CAPTURE_ON_START:
|
||||||
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||||
|
|
||||||
|
head_start_pos = $Head.position
|
||||||
|
|
||||||
|
func _physics_process(delta):
|
||||||
|
if Engine.is_editor_hint():
|
||||||
|
return
|
||||||
|
|
||||||
|
# Increment player tick, used in head bob motion
|
||||||
|
tick += 1
|
||||||
|
|
||||||
|
if UPDATE_PLAYER_ON_PHYS_STEP:
|
||||||
|
move_player(delta)
|
||||||
|
rotate_player(delta)
|
||||||
|
|
||||||
|
if HEAD_BOB:
|
||||||
|
# Only move head when on the floor and moving
|
||||||
|
if velocity && is_on_floor():
|
||||||
|
head_bob_motion()
|
||||||
|
reset_head_bob(delta)
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
if Engine.is_editor_hint():
|
||||||
|
return
|
||||||
|
|
||||||
|
if !UPDATE_PLAYER_ON_PHYS_STEP:
|
||||||
|
move_player(delta)
|
||||||
|
rotate_player(delta)
|
||||||
|
|
||||||
|
func _input(event):
|
||||||
|
if Engine.is_editor_hint():
|
||||||
|
return
|
||||||
|
|
||||||
|
# Listen for mouse movement and check if mouse is captured
|
||||||
|
if event is InputEventMouseMotion && Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||||
|
set_rotation_target(event.relative)
|
||||||
|
|
||||||
|
func set_rotation_target(mouse_motion : Vector2):
|
||||||
|
# Add player target to the mouse -x input
|
||||||
|
rotation_target_player += -mouse_motion.x * KEY_BIND_MOUSE_SENS
|
||||||
|
# Add head target to the mouse -y input
|
||||||
|
rotation_target_head += -mouse_motion.y * KEY_BIND_MOUSE_SENS
|
||||||
|
# Clamp rotation
|
||||||
|
if CLAMP_HEAD_ROTATION:
|
||||||
|
rotation_target_head = clamp(rotation_target_head, deg_to_rad(CLAMP_HEAD_ROTATION_MIN), deg_to_rad(CLAMP_HEAD_ROTATION_MAX))
|
||||||
|
|
||||||
|
func rotate_player(delta):
|
||||||
|
if MOUSE_ACCEL:
|
||||||
|
# Shperical lerp between player rotation and target
|
||||||
|
quaternion = quaternion.slerp(Quaternion(Vector3.UP, rotation_target_player), KEY_BIND_MOUSE_ACCEL * delta)
|
||||||
|
# Same again for head
|
||||||
|
$Head.quaternion = $Head.quaternion.slerp(Quaternion(Vector3.RIGHT, rotation_target_head), KEY_BIND_MOUSE_ACCEL * delta)
|
||||||
|
else:
|
||||||
|
# If mouse accel is turned off, simply set to target
|
||||||
|
quaternion = Quaternion(Vector3.UP, rotation_target_player)
|
||||||
|
$Head.quaternion = Quaternion(Vector3.RIGHT, rotation_target_head)
|
||||||
|
|
||||||
|
func move_player(delta):
|
||||||
|
# Check if not on floor
|
||||||
|
if not is_on_floor():
|
||||||
|
# Reduce speed and accel
|
||||||
|
speed = IN_AIR_SPEED
|
||||||
|
accel = IN_AIR_ACCEL
|
||||||
|
# Add the gravity
|
||||||
|
velocity.y -= gravity * delta
|
||||||
|
else:
|
||||||
|
# Set speed and accel to defualt
|
||||||
|
speed = SPEED
|
||||||
|
accel = ACCEL
|
||||||
|
|
||||||
|
# Handle Jump.
|
||||||
|
if Input.is_action_just_pressed(KEY_BIND_JUMP) and is_on_floor():
|
||||||
|
velocity.y = JUMP_VELOCITY
|
||||||
|
|
||||||
|
# Get the input direction and handle the movement/deceleration.
|
||||||
|
var input_dir = Input.get_vector(KEY_BIND_LEFT, KEY_BIND_RIGHT, KEY_BIND_UP, KEY_BIND_DOWN)
|
||||||
|
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||||
|
|
||||||
|
velocity.x = move_toward(velocity.x, direction.x * speed, accel * delta)
|
||||||
|
velocity.z = move_toward(velocity.z, direction.z * speed, accel * delta)
|
||||||
|
|
||||||
|
move_and_slide()
|
||||||
|
|
||||||
|
func head_bob_motion():
|
||||||
|
var pos = Vector3.ZERO
|
||||||
|
pos.y += sin(tick * HEAD_BOB_FREQUENCY) * HEAD_BOB_AMPLITUDE
|
||||||
|
pos.x += cos(tick * HEAD_BOB_FREQUENCY/2) * HEAD_BOB_AMPLITUDE * 2
|
||||||
|
$Head.position += pos
|
||||||
|
|
||||||
|
func reset_head_bob(delta):
|
||||||
|
# Lerp back to the staring position
|
||||||
|
if $Head.position == head_start_pos:
|
||||||
|
pass
|
||||||
|
$Head.position = lerp($Head.position, head_start_pos, 2 * (1/HEAD_BOB_FREQUENCY) * delta)
|
|
@ -0,0 +1,8 @@
|
||||||
|
@tool
|
||||||
|
extends EditorPlugin
|
||||||
|
|
||||||
|
func _enter_tree():
|
||||||
|
add_custom_type("Basic FPS Player", "CharacterBody3D", preload("Src/basic_player_startup.gd"), preload("Assets/Basic FPS Player.svg"))
|
||||||
|
|
||||||
|
func _exit_tree():
|
||||||
|
remove_custom_type("Basic FPS Player")
|
|
@ -0,0 +1,11 @@
|
||||||
|
[plugin]
|
||||||
|
|
||||||
|
name="Basic FPS Player"
|
||||||
|
description="Adds the \"Basic FPS Player\" node, to kick start any FPS project.
|
||||||
|
Currently version V1.2, features include:
|
||||||
|
- Basic walk and jump
|
||||||
|
- Mouse acceleration
|
||||||
|
- Head bob "
|
||||||
|
author="sammburr"
|
||||||
|
version="V1.2"
|
||||||
|
script="basic_fps_player.gd"
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,22 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="wavefront_obj"
|
||||||
|
importer_version=1
|
||||||
|
type="Mesh"
|
||||||
|
uid="uid://o5s6as3dy3fu"
|
||||||
|
path="res://.godot/imported/hq2_ambience.obj-cbff3595b55da377d76c5b11b247d7e0.mesh"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
files=["res://.godot/imported/hq2_ambience.obj-cbff3595b55da377d76c5b11b247d7e0.mesh"]
|
||||||
|
|
||||||
|
source_file="res://hq2_ambience.obj"
|
||||||
|
dest_files=["res://.godot/imported/hq2_ambience.obj-cbff3595b55da377d76c5b11b247d7e0.mesh", "res://.godot/imported/hq2_ambience.obj-cbff3595b55da377d76c5b11b247d7e0.mesh"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
generate_tangents=true
|
||||||
|
scale_mesh=Vector3(1, 1, 1)
|
||||||
|
offset_mesh=Vector3(0, 0, 0)
|
||||||
|
optimize_mesh=true
|
||||||
|
force_disable_mesh_compression=false
|
|
@ -0,0 +1 @@
|
||||||
|
<svg height="128" width="128" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="124" height="124" rx="14" fill="#363d52" stroke="#212532" stroke-width="4"/><g transform="scale(.101) translate(122 122)"><g fill="#fff"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 813 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H447l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c3 34 55 34 58 0v-86c-3-34-55-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></g></svg>
|
After Width: | Height: | Size: 950 B |
|
@ -0,0 +1,37 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://cpdh748nyf5k6"
|
||||||
|
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://icon.svg"
|
||||||
|
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
|
svg/scale=1.0
|
||||||
|
editor/scale_with_editor_scale=false
|
||||||
|
editor/convert_colors_with_editor_theme=false
|
|
@ -0,0 +1,9 @@
|
||||||
|
[gd_scene load_steps=2 format=3 uid="uid://bmsy8kkc7wvr"]
|
||||||
|
|
||||||
|
[sub_resource type="MultiMesh" id="MultiMesh_3j8n4"]
|
||||||
|
transform_format = 1
|
||||||
|
|
||||||
|
[node name="Map_MultiMeshInstance3D" type="Node3D"]
|
||||||
|
|
||||||
|
[node name="MultiMeshInstance3D" type="MultiMeshInstance3D" parent="."]
|
||||||
|
multimesh = SubResource("MultiMesh_3j8n4")
|
|
@ -0,0 +1,28 @@
|
||||||
|
[gd_scene load_steps=5 format=3 uid="uid://djd50mu74rdrt"]
|
||||||
|
|
||||||
|
[ext_resource type="ArrayMesh" uid="uid://o5s6as3dy3fu" path="res://hq2_ambience.obj" id="1_5rg6w"]
|
||||||
|
[ext_resource type="Script" path="res://addons/Basic FPS Player/Src/basic_player_startup.gd" id="2_0tu55"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://kmyakts4l64t" path="res://addons/Basic FPS Player/Src/basic_player_head.tscn" id="3_rqf4k"]
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_4ycap"]
|
||||||
|
|
||||||
|
[node name="map_CSGMesh3D" type="Node3D"]
|
||||||
|
|
||||||
|
[node name="CSGMesh3D" type="CSGMesh3D" parent="."]
|
||||||
|
use_collision = true
|
||||||
|
mesh = ExtResource("1_5rg6w")
|
||||||
|
|
||||||
|
[node name="Basic FPS Player" type="CharacterBody3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -326.846, 0)
|
||||||
|
script = ExtResource("2_0tu55")
|
||||||
|
|
||||||
|
[node name="Head" type="Node3D" parent="Basic FPS Player" instance=ExtResource("3_rqf4k")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="Basic FPS Player"]
|
||||||
|
shape = SubResource("CapsuleShape3D_4ycap")
|
||||||
|
|
||||||
|
[node name="OmniLight3D" type="OmniLight3D" parent="Basic FPS Player"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 326.846, 0)
|
||||||
|
light_energy = 10.0
|
||||||
|
omni_range = 100.0
|
|
@ -0,0 +1,8 @@
|
||||||
|
[gd_scene load_steps=2 format=3 uid="uid://bq3jmss704f3q"]
|
||||||
|
|
||||||
|
[ext_resource type="ArrayMesh" uid="uid://o5s6as3dy3fu" path="res://hq2_ambience.obj" id="1_dhp4u"]
|
||||||
|
|
||||||
|
[node name="Map_MeshInstance3D" type="Node3D"]
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||||
|
mesh = ExtResource("1_dhp4u")
|
|
@ -0,0 +1,25 @@
|
||||||
|
; Engine configuration file.
|
||||||
|
; It's best edited using the editor UI and not directly,
|
||||||
|
; since the parameters that go here are not all obvious.
|
||||||
|
;
|
||||||
|
; Format:
|
||||||
|
; [section] ; section goes between []
|
||||||
|
; param=value ; assign values to parameters
|
||||||
|
|
||||||
|
config_version=5
|
||||||
|
|
||||||
|
[application]
|
||||||
|
|
||||||
|
config/name="HQA"
|
||||||
|
run/main_scene="res://map_CSGMesh3D.tscn"
|
||||||
|
config/features=PackedStringArray("4.2", "GL Compatibility")
|
||||||
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
[editor_plugins]
|
||||||
|
|
||||||
|
enabled=PackedStringArray("res://addons/Basic FPS Player/plugin.cfg")
|
||||||
|
|
||||||
|
[rendering]
|
||||||
|
|
||||||
|
renderer/rendering_method="gl_compatibility"
|
||||||
|
renderer/rendering_method.mobile="gl_compatibility"
|
Loading…
Reference in New Issue