Skip to content

Commit

Permalink
In-editor tools module
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakarya committed May 29, 2024
1 parent 80476b2 commit 2879337
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ Some parts came from StayAtHomeDev's FPS tutorial. You can find that [here](http
Move with WASD, space to jump, shift to sprint, C to crouch.

**FEATURES:**
- In-air momentum
- Motion smoothing
- FOV smoothing
- Movement animations
- Crouching
- Sprinting
- 2 crosshairs/reticles, one is animated (more to come?)
- Controller/GamePad support (enabled through code, see wiki)
- Extremely configurable
- In-air momentum
- Motion smoothing
- FOV smoothing
- Movement animations
- Crouching
- Sprinting
- 2 crosshairs/reticles, one is animated (more to come?)
- Controller/GamePad support (enabled through code, see wiki)
- In-editor tools (enable editable children to use)

If you make a cool game with this addon, I would love to hear about it!

Expand Down Expand Up @@ -54,3 +56,8 @@ Use the `change_reticle` function on the character.
- Remove the script from the reticle and create a new one. (for some reason you have to do this)
- Edit the reticle to your needs.
- Follow the "how to change reticles" directions to use it.

**How to use the editor tools:**
- Enable editable children on the `CharacterBody` node
- Use the options in the Properties tab to change things
- These changes apply in runtime as well
48 changes: 48 additions & 0 deletions addons/fpc/EditorModule.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@tool
extends Node

# This module affects runtime nad


#TODO: Add descriptions
@export_category("Controller Editor Module")
@export var head_y_rotation : float = 0:
set(new_rotation):
head_y_rotation = new_rotation
HEAD.rotation.y = head_y_rotation
update_configuration_warnings()

@export_group("Nodes")
@export var CHARACTER : CharacterBody3D
@export var head_path : String = "Head" # From this nodes parent node
#@export var CAMERA : Camera3D
#@export var HEADBOB_ANIMATION : AnimationPlayer
#@export var JUMP_ANIMATION : AnimationPlayer
#@export var CROUCH_ANIMATION : AnimationPlayer
#@export var COLLISION_MESH : CollisionShape3D

var HEAD


func _ready():
HEAD = get_node("../" + head_path)
if Engine.is_editor_hint():
pass
else:
HEAD.rotation.y = head_y_rotation

func _process(delta):
if Engine.is_editor_hint():
pass

func _get_configuration_warnings():
var warnings = []

if head_y_rotation > 360:
warnings.append("The head rotation is greater than 360")

if head_y_rotation < 0:
warnings.append("The head rotation is less than 0")

# Returning an empty array gives no warnings
return warnings
6 changes: 5 additions & 1 deletion addons/fpc/character.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[gd_scene load_steps=20 format=3 uid="uid://cc1m2a1obsyn4"]
[gd_scene load_steps=21 format=3 uid="uid://cc1m2a1obsyn4"]

[ext_resource type="Script" path="res://addons/fpc/character.gd" id="1_0t4e8"]
[ext_resource type="Script" path="res://addons/fpc/EditorModule.gd" id="3_v3ckk"]
[ext_resource type="Script" path="res://addons/fpc/debug.gd" id="3_x1wcc"]

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_kp17n"]
Expand Down Expand Up @@ -455,3 +456,6 @@ layout_mode = 2
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
shape = SubResource("SphereShape3D_k4wwl")
target_position = Vector3(0, 0.5, 0)

[node name="EditorModule" type="Node" parent="."]
script = ExtResource("3_v3ckk")
5 changes: 5 additions & 0 deletions test_world.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ uv1_triplanar_sharpness = 0.000850145
[node name="Character" parent="." instance=ExtResource("1_e18vq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)

[node name="Camera" parent="Character/Head" index="0"]
transform = Transform3D(1, 0, 0, 0, 0.999391, -0.0348995, 0, 0.0348995, 0.999391, 0, 0, 0)

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_20rw3")

Expand Down Expand Up @@ -104,3 +107,5 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.5, 3, -15.5)
use_collision = true
size = Vector3(19, 8, 1)
material = SubResource("StandardMaterial3D_7j4uu")

[editable path="Character"]

0 comments on commit 2879337

Please sign in to comment.