├── FPSBasic.gd ├── FPSBasic.tscn ├── LICENSE └── README.md /FPSBasic.gd: -------------------------------------------------------------------------------- 1 | extends KinematicBody 2 | 3 | var speed = 7 4 | var acceleration = 10 5 | var gravity = 0.09 6 | var jump = 10 7 | 8 | var mouse_sensitivity = 0.03 9 | 10 | var direction = Vector3() 11 | var velocity = Vector3() 12 | var fall = Vector3() 13 | 14 | onready var head = $Head 15 | 16 | func _ready(): 17 | Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) 18 | 19 | func _input(event): 20 | 21 | if event is InputEventMouseMotion: 22 | rotate_y(deg2rad(-event.relative.x * mouse_sensitivity)) 23 | head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity)) 24 | head.rotation.x = clamp(head.rotation.x, deg2rad(-90), deg2rad(90)) 25 | 26 | func _physics_process(delta): 27 | 28 | direction = Vector3() 29 | 30 | move_and_slide(fall, Vector3.UP) 31 | 32 | if not is_on_floor(): 33 | fall.y -= gravity 34 | 35 | if Input.is_action_just_pressed("jump") and is_on_floor(): 36 | fall.y = jump 37 | 38 | 39 | if Input.is_action_pressed("move_forward"): 40 | 41 | direction -= transform.basis.z 42 | 43 | elif Input.is_action_pressed("move_backward"): 44 | 45 | direction += transform.basis.z 46 | 47 | if Input.is_action_pressed("move_left"): 48 | 49 | direction -= transform.basis.x 50 | 51 | elif Input.is_action_pressed("move_right"): 52 | 53 | direction += transform.basis.x 54 | 55 | 56 | direction = direction.normalized() 57 | velocity = velocity.linear_interpolate(direction * speed, acceleration * delta) 58 | velocity = move_and_slide(velocity, Vector3.UP) 59 | 60 | -------------------------------------------------------------------------------- /FPSBasic.tscn: -------------------------------------------------------------------------------- 1 | [gd_scene load_steps=4 format=2] 2 | 3 | [ext_resource path="res://scripts/FPSBasic.gd" type="Script" id=1] 4 | 5 | [sub_resource type="CapsuleShape" id=1] 6 | radius = 0.5 7 | height = 1.5 8 | 9 | [sub_resource type="CapsuleMesh" id=2] 10 | radius = 0.5 11 | mid_height = 1.5 12 | 13 | [node name="FPS" type="KinematicBody"] 14 | collision_layer = 2 15 | script = ExtResource( 1 ) 16 | 17 | [node name="CollisionShape" type="CollisionShape" parent="."] 18 | transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 ) 19 | shape = SubResource( 1 ) 20 | 21 | [node name="MeshInstance" type="MeshInstance" parent="."] 22 | transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0 ) 23 | mesh = SubResource( 2 ) 24 | material/0 = null 25 | 26 | [node name="Head" type="Spatial" parent="."] 27 | transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 ) 28 | 29 | [node name="Camera" type="Camera" parent="Head"] 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Garbaj 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | THIS VERSION IS OUTDATED AND BUGGY. USE THIS INSTEAD https://github.com/GarbajYT/godot_updated_fps_controller 2 | --------------------------------------------------------------------------------