Intial commit
This commit is contained in:
		
							
								
								
									
										12
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					# Godot-specific ignores
 | 
				
			||||||
 | 
					.import/
 | 
				
			||||||
 | 
					export.cfg
 | 
				
			||||||
 | 
					export_presets.cfg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Imported translations (automatically generated from CSV files)
 | 
				
			||||||
 | 
					*.translation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Mono-specific ignores
 | 
				
			||||||
 | 
					.mono/
 | 
				
			||||||
 | 
					data_*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										64
									
								
								NewFPS.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								NewFPS.gd
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,64 @@
 | 
				
			|||||||
 | 
					extends KinematicBody
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export var speed = 10 # Player movement speed
 | 
				
			||||||
 | 
					export var mouse_sensitivity = 0.1 # Camera sensitivity
 | 
				
			||||||
 | 
					export var jump = 10
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					onready var head = $Head
 | 
				
			||||||
 | 
					onready var ground_check = $GroundCheck
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var h_acceleration = 6
 | 
				
			||||||
 | 
					var air_acceleration = 1
 | 
				
			||||||
 | 
					var normal_acceleration = 6
 | 
				
			||||||
 | 
					var gravity = 20
 | 
				
			||||||
 | 
					var full_contact = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var direction = Vector3()
 | 
				
			||||||
 | 
					var h_velocity = Vector3()
 | 
				
			||||||
 | 
					var movement = Vector3()
 | 
				
			||||||
 | 
					var gravity_vec = Vector3()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _ready():
 | 
				
			||||||
 | 
						Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _input(event):
 | 
				
			||||||
 | 
						if event is InputEventMouseMotion:
 | 
				
			||||||
 | 
							rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
 | 
				
			||||||
 | 
							head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
 | 
				
			||||||
 | 
							head.rotation.x = clamp(head.rotation.x, deg2rad(-89), deg2rad(89))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _physics_process(delta):
 | 
				
			||||||
 | 
						direction = Vector3()
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						full_contact = ground_check.is_colliding()
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if not is_on_floor():
 | 
				
			||||||
 | 
							gravity_vec += Vector3.DOWN * gravity * delta
 | 
				
			||||||
 | 
							h_acceleration = air_acceleration
 | 
				
			||||||
 | 
						elif is_on_floor() and full_contact:
 | 
				
			||||||
 | 
							gravity_vec = -get_floor_normal() * gravity
 | 
				
			||||||
 | 
							h_acceleration = normal_acceleration
 | 
				
			||||||
 | 
						else:
 | 
				
			||||||
 | 
							gravity_vec = -get_floor_normal()
 | 
				
			||||||
 | 
							h_acceleration = normal_acceleration
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if Input.is_action_just_pressed("jump") and (is_on_floor() or full_contact):
 | 
				
			||||||
 | 
							gravity_vec = Vector3.UP * jump
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if Input.is_action_pressed("move_forward"):
 | 
				
			||||||
 | 
							direction -= transform.basis.z
 | 
				
			||||||
 | 
						elif Input.is_action_pressed("move_back"):
 | 
				
			||||||
 | 
							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)
 | 
				
			||||||
							
								
								
									
										37
									
								
								NewFPS.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								NewFPS.tscn
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,37 @@
 | 
				
			|||||||
 | 
					[gd_scene load_steps=5 format=2]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[ext_resource path="res://NewFPS.gd" type="Script" id=1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[sub_resource type="CapsuleMesh" id=1]
 | 
				
			||||||
 | 
					mid_height = 3.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[sub_resource type="CapsuleShape" id=2]
 | 
				
			||||||
 | 
					height = 3.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[sub_resource type="CylinderShape" id=3]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="NewFPS" type="KinematicBody"]
 | 
				
			||||||
 | 
					script = ExtResource( 1 )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="MeshInstance" type="MeshInstance" parent="."]
 | 
				
			||||||
 | 
					transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0 )
 | 
				
			||||||
 | 
					mesh = SubResource( 1 )
 | 
				
			||||||
 | 
					material/0 = null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="CollisionShape" type="CollisionShape" parent="."]
 | 
				
			||||||
 | 
					transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0 )
 | 
				
			||||||
 | 
					shape = SubResource( 2 )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="Foot" type="CollisionShape" parent="."]
 | 
				
			||||||
 | 
					transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.49618, 0 )
 | 
				
			||||||
 | 
					shape = SubResource( 3 )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="Head" type="Spatial" parent="."]
 | 
				
			||||||
 | 
					transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.53131, 0 )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[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 )
 | 
				
			||||||
							
								
								
									
										3
									
								
								ReadMe.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								ReadMe.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					# Godot FPS Demo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This is a basic FPS Camera and movement system built in Godot v3.2.2
 | 
				
			||||||
							
								
								
									
										25
									
								
								TestMap.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								TestMap.tscn
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					[gd_scene load_steps=4 format=2]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[ext_resource path="res://NewFPS.tscn" type="PackedScene" id=1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[sub_resource type="CubeMesh" id=1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[sub_resource type="BoxShape" id=2]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="TestMap" type="Spatial"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="NewFPS" parent="." instance=ExtResource( 1 )]
 | 
				
			||||||
 | 
					transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0 )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="StaticBody" type="StaticBody" parent="."]
 | 
				
			||||||
 | 
					transform = Transform( 25, 0, 0, 0, 1, 0, 0, 0, 25, 0, -2.14964, 0 )
 | 
				
			||||||
 | 
					__meta__ = {
 | 
				
			||||||
 | 
					"_edit_group_": true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="MeshInstance" type="MeshInstance" parent="StaticBody"]
 | 
				
			||||||
 | 
					mesh = SubResource( 1 )
 | 
				
			||||||
 | 
					material/0 = null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
 | 
				
			||||||
 | 
					shape = SubResource( 2 )
 | 
				
			||||||
							
								
								
									
										7
									
								
								default_env.tres
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								default_env.tres
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					[gd_resource type="Environment" load_steps=2 format=2]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[sub_resource type="ProceduralSky" id=1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[resource]
 | 
				
			||||||
 | 
					background_mode = 2
 | 
				
			||||||
 | 
					background_sky = SubResource( 1 )
 | 
				
			||||||
							
								
								
									
										34
									
								
								icon.png.import
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								icon.png.import
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,34 @@
 | 
				
			|||||||
 | 
					[remap]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					importer="texture"
 | 
				
			||||||
 | 
					type="StreamTexture"
 | 
				
			||||||
 | 
					path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
 | 
				
			||||||
 | 
					metadata={
 | 
				
			||||||
 | 
					"vram_texture": false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[deps]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					source_file="res://icon.png"
 | 
				
			||||||
 | 
					dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[params]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					compress/mode=0
 | 
				
			||||||
 | 
					compress/lossy_quality=0.7
 | 
				
			||||||
 | 
					compress/hdr_mode=0
 | 
				
			||||||
 | 
					compress/bptc_ldr=0
 | 
				
			||||||
 | 
					compress/normal_map=0
 | 
				
			||||||
 | 
					flags/repeat=0
 | 
				
			||||||
 | 
					flags/filter=true
 | 
				
			||||||
 | 
					flags/mipmaps=false
 | 
				
			||||||
 | 
					flags/anisotropic=false
 | 
				
			||||||
 | 
					flags/srgb=2
 | 
				
			||||||
 | 
					process/fix_alpha_border=true
 | 
				
			||||||
 | 
					process/premult_alpha=false
 | 
				
			||||||
 | 
					process/HDR_as_SRGB=false
 | 
				
			||||||
 | 
					process/invert_color=false
 | 
				
			||||||
 | 
					stream=false
 | 
				
			||||||
 | 
					size_limit=0
 | 
				
			||||||
 | 
					detect_3d=true
 | 
				
			||||||
 | 
					svg/scale=1.0
 | 
				
			||||||
							
								
								
									
										52
									
								
								project.godot
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								project.godot
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,52 @@
 | 
				
			|||||||
 | 
					; 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=4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					_global_script_classes=[  ]
 | 
				
			||||||
 | 
					_global_script_class_icons={
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[application]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					config/name="fps-demo"
 | 
				
			||||||
 | 
					run/main_scene="res://TestMap.tscn"
 | 
				
			||||||
 | 
					config/icon="res://icon.png"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[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,"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)
 | 
				
			||||||
 | 
					 ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					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)
 | 
				
			||||||
 | 
					 ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					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)
 | 
				
			||||||
 | 
					 ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					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)
 | 
				
			||||||
 | 
					 ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[rendering]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					environment/default_environment="res://default_env.tres"
 | 
				
			||||||
		Reference in New Issue
	
	Block a user