├── LICENSE ├── NewFPSCont.gd ├── NewFPSCont.tscn └── README.md /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 | -------------------------------------------------------------------------------- /NewFPSCont.gd: -------------------------------------------------------------------------------- 1 | extends KinematicBody 2 | 3 | var speed = 10 4 | var h_acceleration = 6 5 | var air_acceleration = 1 6 | var normal_acceleration = 6 7 | var gravity = 20 8 | var jump = 10 9 | var full_contact = false 10 | 11 | var mouse_sensitivity = 0.03 12 | 13 | var direction = Vector3() 14 | var h_velocity = Vector3() 15 | var movement = Vector3() 16 | var gravity_vec = Vector3() 17 | 18 | onready var head = $Head 19 | onready var ground_check = $GroundCheck 20 | 21 | func _ready(): 22 | pass 23 | 24 | func _input(event): 25 | if event is InputEventMouseMotion: 26 | rotate_y(deg2rad(-event.relative.x * mouse_sensitivity)) 27 | head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity)) 28 | head.rotation.x = clamp(head.rotation.x, deg2rad(-89), deg2rad(89)) 29 | 30 | func _physics_process(delta): 31 | 32 | direction = Vector3() 33 | 34 | full_contact = ground_check.is_colliding() 35 | 36 | if not is_on_floor(): 37 | gravity_vec += Vector3.DOWN * gravity * delta 38 | h_acceleration = air_acceleration 39 | elif is_on_floor() and full_contact: 40 | gravity_vec = -get_floor_normal() * gravity 41 | h_acceleration = normal_acceleration 42 | else: 43 | gravity_vec = -get_floor_normal() 44 | h_acceleration = normal_acceleration 45 | 46 | if Input.is_action_just_pressed("jump") and (is_on_floor() or ground_check.is_colliding()): 47 | gravity_vec = Vector3.UP * jump 48 | 49 | if Input.is_action_pressed("move_forward"): 50 | direction -= transform.basis.z 51 | elif Input.is_action_pressed("move_backward"): 52 | direction += transform.basis.z 53 | if Input.is_action_pressed("move_left"): 54 | direction -= transform.basis.x 55 | elif Input.is_action_pressed("move_right"): 56 | direction += transform.basis.x 57 | 58 | direction = direction.normalized() 59 | h_velocity = h_velocity.linear_interpolate(direction * speed, h_acceleration * delta) 60 | movement.z = h_velocity.z + gravity_vec.z 61 | movement.x = h_velocity.x + gravity_vec.x 62 | movement.y = gravity_vec.y 63 | 64 | move_and_slide(movement, Vector3.UP) 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /NewFPSCont.tscn: -------------------------------------------------------------------------------- 1 | [gd_scene load_steps=6 format=2] 2 | 3 | [ext_resource path="res://scripts/NewFPSCont.gd" type="Script" id=1] 4 | [ext_resource path="res://assets/generic.material" type="Material" id=4] 5 | 6 | [sub_resource type="CapsuleMesh" id=1] 7 | material = ExtResource( 4 ) 8 | mid_height = 3.0 9 | 10 | [sub_resource type="CapsuleShape" id=2] 11 | height = 3.0 12 | 13 | [sub_resource type="CylinderShape" id=3] 14 | 15 | [node name="NewFPSCont" type="KinematicBody"] 16 | script = ExtResource( 1 ) 17 | 18 | [node name="MeshInstance" type="MeshInstance" parent="."] 19 | transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0 ) 20 | cast_shadow = 0 21 | mesh = SubResource( 1 ) 22 | material/0 = null 23 | 24 | [node name="CollisionShape" type="CollisionShape" parent="."] 25 | transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0 ) 26 | shape = SubResource( 2 ) 27 | 28 | [node name="Foot" type="CollisionShape" parent="."] 29 | transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.5, 0 ) 30 | shape = SubResource( 3 ) 31 | 32 | [node name="Head" type="Spatial" parent="."] 33 | transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.25, 0 ) 34 | 35 | [node name="Camera" type="Camera" parent="Head"] 36 | 37 | [node name="GroundCheck" type="RayCast" parent="."] 38 | transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0 ) 39 | enabled = true 40 | cast_to = Vector3( 0, -1.5, 0 ) 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OUTDATED AND BUGGY. USE THIS INSTEAD https://github.com/GarbajYT/godot_updated_fps_controller 2 | --------------------------------------------------------------------------------