-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,17 @@ | ||
using MoreMountains.Tools; | ||
using MoreMountains.TopDownEngine; | ||
using UnityEngine; | ||
|
||
public class CharacterJumpMarble : CharacterAbility | ||
{ | ||
public float JumpForce = 100; | ||
|
||
protected override void HandleInput() | ||
{ | ||
if (AbilityAuthorized && | ||
_condition.CurrentState == CharacterStates.CharacterConditions.Normal && | ||
_controller.Grounded && | ||
_inputManager.JumpButton.State.CurrentState == MMInput.ButtonStates.ButtonDown) | ||
_controller.AddForce(JumpForce * Vector3.up); | ||
} | ||
} |
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,22 @@ | ||
using MoreMountains.TopDownEngine; | ||
|
||
public class MarbleCharacter : Character | ||
{ | ||
protected override void Initialization() | ||
{ | ||
base.Initialization(); | ||
CharacterDimension = CharacterDimensions.Type3D; | ||
} | ||
|
||
public override void Freeze() | ||
{ | ||
_controller.SetKinematic(true); | ||
ConditionState.ChangeState(CharacterStates.CharacterConditions.Frozen); | ||
} | ||
|
||
public override void UnFreeze() | ||
{ | ||
_controller.SetKinematic(false); | ||
ConditionState.ChangeState(CharacterStates.CharacterConditions.Normal); | ||
} | ||
} |
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,58 @@ | ||
using MoreMountains.TopDownEngine; | ||
using UnityEngine; | ||
|
||
// Physics driven marble controller. Requires dynamic Rigidbody and a sphere collider | ||
public class TopDownControllerMarble : TopDownController | ||
{ | ||
// grounded check from Catlike Coding's movement tutorial https://catlikecoding.com/unity/tutorials/movement/physics/ | ||
[Range(0f, 90f)] | ||
public float MaxGroundAngle = 45f; | ||
[Tooltip("the speed at which external forces get lerped to zero")] | ||
public float ImpactFalloff = 5f; | ||
private Rigidbody _rigidbody; | ||
private float _minGroundDotProduct; | ||
|
||
private void OnValidate() | ||
{ | ||
_minGroundDotProduct = Mathf.Cos(MaxGroundAngle * Mathf.Deg2Rad); | ||
} | ||
|
||
protected override void Awake() | ||
{ | ||
base.Awake(); | ||
OnValidate(); | ||
_rigidbody = GetComponent<Rigidbody>(); | ||
} | ||
|
||
private void OnCollisionEnter(Collision collision) { EvaluateCollision(collision); } | ||
private void OnCollisionStay(Collision collision) { EvaluateCollision(collision); } | ||
private void EvaluateCollision(Collision collision) | ||
{ | ||
for (var i = 0; i < collision.contactCount; i++) | ||
{ | ||
var normal = collision.GetContact(i).normal; | ||
Grounded |= normal.y >= _minGroundDotProduct; | ||
} | ||
} | ||
|
||
public override void Impact(Vector3 direction, float force) { _impact += direction.normalized * force; } | ||
|
||
private void ApplyImpact() | ||
{ | ||
if (_impact.magnitude > .2f) _rigidbody.AddForce(_impact); | ||
_impact = Vector3.Lerp(_impact, Vector3.zero, ImpactFalloff * Time.deltaTime); | ||
} | ||
|
||
public override void AddForce(Vector3 movement) { Impact(movement, movement.magnitude); } | ||
|
||
public override void SetMovement(Vector3 movement) { CurrentMovement = movement; } | ||
|
||
protected override void FixedUpdate() | ||
{ | ||
ApplyImpact(); | ||
_rigidbody.AddForce(CurrentMovement); | ||
Grounded = false; | ||
} | ||
|
||
public override void SetKinematic(bool state) { _rigidbody.isKinematic = state; } | ||
} |
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,19 @@ | ||
using MoreMountains.TopDownEngine; | ||
using UnityEngine; | ||
|
||
public class UnparentAndRotateToMatchWeapon : MonoBehaviour | ||
{ | ||
private CharacterHandleWeapon _characterHandleWeapon; | ||
|
||
private void Awake() | ||
{ | ||
_characterHandleWeapon = GetComponentInParent<Character>().FindAbility<CharacterHandleWeapon>(); | ||
transform.parent = null; | ||
} | ||
|
||
private void Update() | ||
{ | ||
if (_characterHandleWeapon.CurrentWeapon) | ||
transform.rotation = Quaternion.Euler(_characterHandleWeapon.CurrentWeapon.transform.rotation.eulerAngles.y * Vector3.up); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.