Skip to content

Commit

Permalink
Merge pull request #12 from eviltwo/more-physics-action
Browse files Browse the repository at this point in the history
Improved physical actions
  • Loading branch information
eviltwo authored Aug 3, 2024
2 parents 41ae74c + da2328b commit f498e88
Show file tree
Hide file tree
Showing 132 changed files with 14,193 additions and 204 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ActionGameCore
3Dゲームにおけるキャラクターの基本動作のスクリプトです。アクションゲームだけでなく、謎解きゲームや散歩ゲームなどキャラクターが移動するゲーム全般で使えます。

![chara](https://github.com/eviltwo/ActionGameCore/assets/7721151/6921cd9a-26cf-404f-8d62-856556d62d1f)
![action](https://github.com/user-attachments/assets/c8a67533-cd89-4db9-bcca-5d2db4c2f2d3)

# 特徴
- キャラクターはRigidbodyで動き、カメラの向きに合わせて前後左右に歩きます。
Expand All @@ -14,13 +14,13 @@
- 入力処理はInputSystemに対応しています。

# パッケージ一覧 (UPMでインポートできます)
### CharacterControls v0.9.0
### CharacterControls v0.10.0
キャラクターの歩行・ジャンプ。
```
https://github.com/eviltwo/ActionGameCore.git?path=src/ActionGameCore/Assets/CharacterControls
```

### CameraControls v1.6.0
### CameraControls v1.6.3
FPSとTPS視点のカメラ。
```
https://github.com/eviltwo/ActionGameCore.git?path=src/ActionGameCore/Assets/CameraControls
Expand Down
4 changes: 4 additions & 0 deletions src/ActionGameCore/Assets/CameraControls/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.6.3] - 2024-08-04
### Added
- Added TPS camera effector for character movement.

## [1.6.2] - 2024-07-11
### Changed
- Change camera rotation speed according to time scale.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using UnityEngine;

namespace CameraControls.Controllers.Effects
{
public class TPSCameraEffector : MonoBehaviour
{
[SerializeField]
public TPSCameraController Controller = null;

private Movement _movement;
private Transform _target;
private GameObject _handle;

private void Reset()
{
Controller = GetComponent<TPSCameraController>();
}

private void OnDestroy()
{
if (Controller != null && _target != null)
{
Controller.Target = _target;
}
if (_handle != null)
{
Destroy(_handle);
}
}

private void Update()
{
if (_movement != null)
{
_movement.Update(Time.deltaTime);
if (_movement.IsDone())
{
Controller.Target = _target;
_target = null;
_movement = null;
}
}
}

public void PlayLinearMove(float duration)
{
if (_movement != null)
{
return;
}

var handle = GetOrCreateHandle();
handle.transform.position = Controller.transform.position;
handle.transform.rotation = Controller.transform.rotation;
_target = Controller.Target;
Controller.Target = handle.transform;
_movement = new LinearMovement(_target, handle.transform, duration);
}

private GameObject GetOrCreateHandle()
{
if (_handle == null)
{
_handle = new GameObject("TPSCameraEffector Handle");
}
return _handle;
}

private abstract class Movement
{
protected Transform Target { get; }
public Transform Handle { get; }
public Movement(Transform target, Transform handle)
{
Target = target;
Handle = handle;
}

public abstract void Update(float deltaTime);

public abstract bool IsDone();
}

private class LinearMovement : Movement
{
private readonly Vector3 _start;
private readonly float _duration;
private float _elapsedTime;
public LinearMovement(Transform target, Transform handle, float duration)
: base(target, handle)
{
_start = target.position;
_duration = duration;
}

public override void Update(float deltaTime)
{
_elapsedTime += deltaTime;
var t = _elapsedTime / _duration;
Handle.position = Vector3.Lerp(_start, Target.position, t);
}

public override bool IsDone()
{
return _elapsedTime > _duration;
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public enum OffsetRotationType
[SerializeField]
public LayerMask WallLayerMask = ~0;

[SerializeField]
public int SmoothingFrameCount = 2;

[SerializeField]
private bool _lockAndHideCursor = true;

Expand Down
2 changes: 1 addition & 1 deletion src/ActionGameCore/Assets/CameraControls/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.eviltwo.camera-controls",
"displayName": "Camera Controls",
"version": "1.6.2",
"version": "1.6.3",
"unity": "2022.3",
"description": "Camera movements for FPS and TPS.",
"author": {
Expand Down
7 changes: 7 additions & 0 deletions src/ActionGameCore/Assets/CharacterControls/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [0.10.0] - 2024-08-04
### Changed
- The character's movement process has been subdivided into the Module class.
### Added
- Added Pull up module.
- Added character animator controller for each modules.

## [0.9.0] - 2024-07-07
### Changed
- Changed to use PlayerInput component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if ENABLE_INPUT_SYSTEM
using System.Collections.Generic;
using CharacterControls.Movements;
using UnityEngine;
using UnityEngine.InputSystem;
Expand All @@ -16,11 +17,11 @@ public class CharacterMoveInput : MonoBehaviour
[SerializeField]
private InputActionReference _jumpActionReference = null;

public IMoveController MoveController { get; set; }
public List<IInputReceiver<Vector2>> _vector2Receivers = new List<IInputReceiver<Vector2>>();
public List<IInputReceiver<float>> _floatReceivers = new List<IInputReceiver<float>>();

private void Start()
{
MoveController = GetComponent<IMoveController>();
PlayerInput.onActionTriggered += OnActionTriggerd;
}

Expand All @@ -29,6 +30,14 @@ private void OnDestroy()
PlayerInput.onActionTriggered -= OnActionTriggerd;
}

private void Update()
{
_vector2Receivers.Clear();
GetComponentsInChildren(_vector2Receivers);
_floatReceivers.Clear();
GetComponentsInChildren(_floatReceivers);
}

private void OnActionTriggerd(InputAction.CallbackContext context)
{
if (_moveActionReference != null && context.action.name == _moveActionReference.action.name)
Expand All @@ -45,14 +54,19 @@ private void OnActionTriggerd(InputAction.CallbackContext context)
private void OnMove(InputAction.CallbackContext context)
{
var value = context.ReadValue<Vector2>();
MoveController.SetMoveInput(value);
var count = _vector2Receivers.Count;
for (var i = 0; i < count; i++)
{
_vector2Receivers[i].OnReceiveInput("Move", value);
}
}

private void OnJump(InputAction.CallbackContext context)
{
if (context.performed && context.startTime > Time.realtimeSinceStartup - 0.5f)
var count = _floatReceivers.Count;
for (var i = 0; i < count; i++)
{
MoveController.SetJumpInput(1);
_floatReceivers[i].OnReceiveInput("Jump", context.performed ? 1f : 0f);
}
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using CharacterControls.Movements.Modules;
using UnityEngine;

namespace CharacterControls.Movements.Animations
{
public class CharacterJumpAnimatorController : MonoBehaviour
{
[SerializeField]
public Animator Animator = null;

[SerializeField]
public CharacterJumpModule JumpModule = null;

[SerializeField]
public string JumpAnimatorParameterTrigger = "OnJump";

private void Reset()
{
Animator = GetComponentInChildren<Animator>();
JumpModule = GetComponentInParent<CharacterJumpModule>();
}

private void Start()
{
if (JumpModule != null)
{
JumpModule.OnJump.AddListener(OnJump);
}
}

private void OnDestroy()
{
if (JumpModule != null)
{
JumpModule.OnJump.RemoveListener(OnJump);
}
}

private void OnJump()
{
Animator.SetTrigger(JumpAnimatorParameterTrigger);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f498e88

Please sign in to comment.