Skip to content

Commit

Permalink
Merge branch 'main' into addon
Browse files Browse the repository at this point in the history
# Conflicts:
#	icon.svg.import
  • Loading branch information
scriptsengineer committed Mar 27, 2024
2 parents 8779943 + 1c343bf commit 8b1978c
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 53 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/.asset-template-csharp-addon.json.hb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"title": "Character Controller C#",
"description": "Modular Character Controller for Godot 4. \nIncludes FPS version with headbob and camera movement. \n(Walk, Crouch, Sprint, Swim and Fly Mode).\nC# Base on https://godotengine.org/asset-library/asset/1567",
"category_id": "6",
"godot_version": "4.1",
"version_string": "{{ env.PLUGIN_VERSION }}",
"cost": "MIT",
"download_provider": "GitHub",
"download_commit": "{{ env.GITHUB_SHA }}",
"browse_url": "{{ context.repository.html_url }}",
"issues_url": "{{ context.repository.html_url }}/issues",
"icon_url": "https://raw.githubusercontent.com/expressobits/character-controller/4c41093cd0f010caa411819c679c6befbc5b3480/icon.svg"
}
51 changes: 51 additions & 0 deletions .github/workflows/push_csharp_addon_to_asset_lib .yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Push CSharp Addon To Asset Lib"
on:
workflow_dispatch:
inputs:
plugin_version:
description: 'Plugin version number:'
required: true
type: string
default: '1.0.0'
push:
branches: [ csharp-addon ]

env:
PLUGIN_VERSION: 0.0.1

jobs:

publish:
# needs: [env-setup]
runs-on: ubuntu-latest
name: Publish new version to asset lib

steps:
- name: Checkout
uses: actions/checkout@v3

- name: set_plugin_version
id: set_plugin_version
run: |
VERSION=$(grep version= addons/character-controller/plugin.cfg | cut -d "=" -f 2 | tr -d '"')
echo "PLUGIN_VERSION=${VERSION}" >> $GITHUB_ENV
- name: Godot Asset Lib
# You may pin to the exact commit or the version.
# uses: deep-entertainment/godot-asset-lib-action@81addbb4db62199a69e4aa5535741a8928d6abb6
uses: deep-entertainment/[email protected]
with:
action: addEdit
# Godot asset lib username
username: expressobits
# Godot asset lib password
password: ${{ secrets.GODOT_ASSET_LIB_PASSWORD }}
# ID of the asset in the asset store
assetId: 2121
# Path to asset template file
assetTemplate: .github/workflows/.asset-template-csharp-addon.json.hb
# Godot asset lib base url
baseUrl: https://godotengine.org/asset-library/api

- name: Debug Godot Asset Lib
run: echo $PLUGIN_VERSION
2 changes: 2 additions & 0 deletions addons/character-controller/abilities/crouch_ability_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class_name CrouchAbility3D
## Collider height when crouch deactived
@export var default_height := 2.0

var crouch_factor : float

## Applies slow if crouch is enabled
func get_speed_modifier() -> float:
Expand All @@ -33,4 +34,5 @@ func apply(velocity: Vector3, speed : float, is_on_floor : bool, direction : Vec
elif not head_check.is_colliding():
collision.shape.height += delta * 8
collision.shape.height = clamp(collision.shape.height , height_in_crouch, default_height)
crouch_factor = (default_height - height_in_crouch) - (collision.shape.height - height_in_crouch)/ (default_height - height_in_crouch)
return velocity
52 changes: 28 additions & 24 deletions addons/character-controller/core/character_controller_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -68,74 +68,74 @@ signal stopped_floating
## Controller Gravity Multiplier
## The higher the number, the faster the controller will fall to the ground and
## your jump will be shorter.
@export var gravity_multiplier := 3.0
@export var gravity_multiplier : float = 3.0

## Controller base speed
## Note: this speed is used as a basis for abilities to multiply their
## respective values, changing it will have consequences on [b]all abilities[/b]
## that use velocity.
@export var speed := 10
@export var speed : float = 10.0

## Time for the character to reach full speed
@export var acceleration := 8
@export var acceleration : float = 8.0

## Time for the character to stop walking
@export var deceleration := 10
@export var deceleration : float = 10.0

## Sets control in the air
@export var air_control := 0.3
@export var air_control : float = 0.3


@export_group("Sprint")

## Speed to be multiplied when active the ability
@export var sprint_speed_multiplier := 1.6
@export var sprint_speed_multiplier : float = 1.6


@export_group("Footsteps")

## Maximum counter value to be computed one step
@export var step_lengthen := 0.7
@export var step_lengthen : float = 0.7

## Value to be added to compute a step, each frame that the character is walking this value
## is added to a counter
@export var step_interval := 6.0
@export var step_interval : float = 6.0


@export_group("Crouch")

## Collider height when crouch actived
@export var height_in_crouch := 1.0
@export var height_in_crouch : float = 1.0

## Speed multiplier when crouch is actived
@export var crouch_speed_multiplier := 0.7
@export var crouch_speed_multiplier : float = 0.7


@export_group("Jump")

## Jump/Impulse height
@export var jump_height := 10
@export var jump_height : float = 10.0


@export_group("Fly")

## Speed multiplier when fly mode is actived
@export var fly_mode_speed_modifier := 2
@export var fly_mode_speed_modifier : float = 2.0


@export_group("Swim")

## Minimum height for [CharacterController3D] to be completely submerged in water.
@export var submerged_height := 0.36
@export var submerged_height : float = 0.36

## Minimum height for [CharacterController3D] to be float in water.
@export var floating_height := 0.75
@export var floating_height : float = 0.75

## Speed multiplier when floating water
@export var on_water_speed_multiplier := 0.75
@export var on_water_speed_multiplier : float = 0.75

## Speed multiplier when submerged water
@export var submerged_speed_multiplier := 0.5
@export var submerged_speed_multiplier : float = 0.5


@export_group("Abilities")
Expand All @@ -155,7 +155,7 @@ var _step_cycle : float = 0
var _next_step : float = 0

## Character controller horizontal speed.
var _horizontal_velocity
var _horizontal_velocity : Vector3

## Base transform node to direct player movement
## Used to differentiate fly mode/swim moves from regular character movement.
Expand Down Expand Up @@ -189,7 +189,7 @@ var _direction_base_node : Node3D
@onready var swim_ability: SwimAbility3D = get_node(NodePath("Swim Ability 3D"))

## Stores normal speed
@onready var _normal_speed: int = speed
@onready var _normal_speed : float = speed

## True if in the last frame it was on the ground
var _last_is_on_floor := false
Expand Down Expand Up @@ -220,7 +220,7 @@ func move(_delta: float, input_axis := Vector2.ZERO, input_jump := false, input_
jump_ability.set_active(input_jump and is_on_floor() and not head_check.is_colliding())
walk_ability.set_active(not is_fly_mode() and not swim_ability.is_floating())
crouch_ability.set_active(input_crouch and is_on_floor() and not is_floating() and not is_submerged() and not is_fly_mode())
sprint_ability.set_active(input_sprint and is_on_floor() and input_axis.x >= 0.5 and !is_crouching() and not is_fly_mode() and not swim_ability.is_floating() and not swim_ability.is_submerged())
sprint_ability.set_active(input_sprint and is_on_floor() and input_axis.y >= 0.5 and !is_crouching() and not is_fly_mode() and not swim_ability.is_floating() and not swim_ability.is_submerged())

var multiplier = 1.0
for ability in _abilities:
Expand Down Expand Up @@ -321,7 +321,7 @@ func _start_variables():

func _check_landed():
if is_on_floor() and not _last_is_on_floor:
emit_signal("landed")
_on_landed()
_reset_step()
_last_is_on_floor = is_on_floor()

Expand All @@ -334,13 +334,13 @@ func _check_step(_delta):
func _direction_input(input : Vector2, input_down : bool, input_up : bool, aim_node : Node3D) -> Vector3:
_direction = Vector3()
var aim = aim_node.get_global_transform().basis
if input.x >= 0.5:
if input.y >= 0.5:
_direction -= aim.z
if input.x <= -0.5:
_direction += aim.z
if input.y <= -0.5:
_direction += aim.z
if input.x <= -0.5:
_direction -= aim.x
if input.y >= 0.5:
if input.x >= 0.5:
_direction += aim.x
# NOTE: For free-flying and swimming movements
if is_fly_mode() or is_floating():
Expand Down Expand Up @@ -395,6 +395,10 @@ func _on_jumped():
emit_signal("jumped")


func _on_landed():
emit_signal("landed")


func _on_swim_ability_emerged():
emit_signal("emerged")

Expand Down
15 changes: 8 additions & 7 deletions addons/character-controller/fps/bob/head_bob.gd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var speed : float = 0
var original_position : Vector3

## Store original rotation of head for headbob reference
var original_rotation : Vector3
var original_rotation : Quaternion

## Actual cycle x of step headbob
var cycle_position_x: float = 0
Expand All @@ -69,7 +69,7 @@ var step_interval: float = 0

func _ready():
original_position = head.position
original_rotation = head.rotation
original_rotation = head.quaternion


## Setup bob with bob base interval
Expand All @@ -96,10 +96,10 @@ func head_bob_process(horizontal_velocity:Vector3, input_axis:Vector2, is_sprint
if is_sprint:
input_axis *= 2
if rotation_to_move:
new_rotation += _head_bob_rotation(input_axis.x, input_axis.y, _delta)
new_rotation += _head_bob_rotation(input_axis.y, input_axis.x, _delta)

head.position = new_position
head.rotation = new_rotation
head.quaternion = new_rotation


## Apply headbob jump
Expand All @@ -114,9 +114,10 @@ func reset_cycles():
cycle_position_y = 0


func _head_bob_rotation(x, z, _delta) -> Vector3:
var target_rotation = Vector3(x * angle_limit_for_rotation, 0.0, -z * angle_limit_for_rotation)
return lerp(head.rotation, target_rotation, speed_rotation * _delta)
func _head_bob_rotation(x, z, _delta) -> Quaternion:
var target_rotation : Quaternion
target_rotation.from_euler(Vector3(x * angle_limit_for_rotation, 0.0, -z * angle_limit_for_rotation))
return lerp(head.quaternion, target_rotation, speed_rotation * _delta)


func _do_head_bob(speed: float, delta: float) -> Vector3:
Expand Down
35 changes: 24 additions & 11 deletions addons/character-controller/fps/fps_controller_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class_name FPSController3D
@export_group("Mouse")

## Mouse Sensitivity
@export var mouse_sensitivity := 2.0
@export var mouse_sensitivity := 2.0:
set(value):
if head != null:
head.mouse_sensitivity = value

## Maximum vertical angle the head can aim
@export var vertical_angle_limit := 90.0
Expand All @@ -36,7 +39,10 @@ class_name FPSController3D
@export_group("Head Bob - Steps")

## Enables bob for made steps
@export var step_bob_enabled := true
@export var step_bob_enabled := true:
set(value):
if head_bob != null:
head_bob.step_bob_enabled = value

## Difference of step bob movement between vertical and horizontal angle
@export var vertical_horizontal_ratio = 2
Expand All @@ -45,13 +51,19 @@ class_name FPSController3D
@export_group("Head Bob - Jump")

## Enables bob for made jumps
@export var jump_bob_enabled := true
@export var jump_bob_enabled := true:
set(value):
if head_bob != null:
head_bob.jump_bob_enabled = value


@export_group("Head Bob - Rotation When Move (Quake Like)")

## Enables camera angle for the direction the character controller moves
@export var rotation_to_move := true
@export var rotation_to_move := true:
set(value):
if head_bob != null:
head_bob.rotation_to_move = value

## Speed at which the camera angle moves
@export var speed_rotation := 4.0
Expand All @@ -62,15 +74,15 @@ class_name FPSController3D
## [HeadMovement3D] reference, where the rotation of the camera sight is calculated
@onready var head: HeadMovement3D = get_node(NodePath("Head"))

## Camera3D reference
@onready var camera: Camera3D = get_node(NodePath("Head/Camera"))
## First Person Camera3D reference
@onready var first_person_camera_reference : Marker3D = get_node(NodePath("Head/FirstPersonCameraReference"))

## Third Person Camera3D reference
@onready var third_person_camera_reference : Marker3D = get_node(NodePath("Head/ThirdPersonCameraReference"))

## HeadBob reference
@onready var head_bob: HeadBob = get_node(NodePath("Head/Head Bob"))

## Stores normal fov from camera fov
@onready var normal_fov: float = camera.fov


## Configure mouse sensitivity, rotation limit angle and head bob
## After call the base class setup [CharacterController3D].
Expand Down Expand Up @@ -103,8 +115,9 @@ func move(_delta: float, input_axis := Vector2.ZERO, input_jump := false, input_
else:
_direction_base_node = self
super.move(_delta, input_axis, input_jump, input_crouch, input_sprint, input_swim_down, input_swim_up)
if not is_fly_mode() and not swim_ability.is_floating() and not swim_ability.is_submerged():
camera.set_fov(lerp(camera.fov, normal_fov, _delta * fov_change_speed))
# TODO Make in exemple this
# if not is_fly_mode() and not swim_ability.is_floating() and not swim_ability.is_submerged()
# camera.set_fov(lerp(camera.fov, normal_fov, _delta * fov_change_speed))
_check_head_bob(_delta, input_axis)


Expand Down
12 changes: 7 additions & 5 deletions addons/character-controller/fps/fps_controller_3d.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ angle_limit_for_rotation = 0.1
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.64, 0)
script = ExtResource("3_pqlf6")

[node name="Camera" type="Camera3D" parent="Head" index="0"]
current = true

[node name="Head Bob" type="Node" parent="Head" index="1"]
[node name="Head Bob" type="Node" parent="Head" index="0"]
script = ExtResource("4_6ym6a")
head_path = NodePath("../Camera")
head_path = NodePath("../FirstPersonCameraReference")
bob_curve = ExtResource("5_cv58a")

[node name="FirstPersonCameraReference" type="Marker3D" parent="Head" index="1"]

[node name="ThirdPersonCameraReference" type="Marker3D" parent="Head" index="2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 4)
2 changes: 1 addition & 1 deletion addons/character-controller/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ description="Modular Character Controller for Godot 4.
Includes FPS version with headbob and camera movement.
(Walk, Crouch, Sprint, Swim and Fly Mode)."
author="Expresso Bits and Whimfoome"
version="2.1.6"
version="2.1.7"
script="plugin.gd"
Loading

0 comments on commit 8b1978c

Please sign in to comment.