Skip to content

Commit

Permalink
Adds MarbleCharacter
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderGheorghe committed Aug 25, 2022
1 parent 951f12d commit b3ea4d6
Show file tree
Hide file tree
Showing 13 changed files with 933 additions and 0 deletions.
757 changes: 757 additions & 0 deletions MarbleCharacter/MarbleCharacter.prefab

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions MarbleCharacter/MarbleCharacter.prefab.meta

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

Binary file added MarbleCharacter/MarbleCharacter.unitypackage
Binary file not shown.
8 changes: 8 additions & 0 deletions MarbleCharacter/Scripts.meta

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

17 changes: 17 additions & 0 deletions MarbleCharacter/Scripts/CharacterJumpMarble.cs
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);
}
}
11 changes: 11 additions & 0 deletions MarbleCharacter/Scripts/CharacterJumpMarble.cs.meta

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

22 changes: 22 additions & 0 deletions MarbleCharacter/Scripts/MarbleCharacter.cs
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);
}
}
11 changes: 11 additions & 0 deletions MarbleCharacter/Scripts/MarbleCharacter.cs.meta

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

58 changes: 58 additions & 0 deletions MarbleCharacter/Scripts/TopDownControllerMarble.cs
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; }
}
11 changes: 11 additions & 0 deletions MarbleCharacter/Scripts/TopDownControllerMarble.cs.meta

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

19 changes: 19 additions & 0 deletions MarbleCharacter/Scripts/UnparentAndRotateToMatchWeapon.cs
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);
}
}
11 changes: 11 additions & 0 deletions MarbleCharacter/Scripts/UnparentAndRotateToMatchWeapon.cs.meta

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

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This repository contains community-created extensions for the TopDown Engine, Mo
* **GrapplingHook**, _by AlexanderGheorghe_, : 3D grappling hook implementation with [rope animation](https://youtu.be/tPtKNvifpj0)
* **GridPathfinding**, _by AlexanderGheorghe_, : grid versions of CharacterPathfinder3D and CharacterPathfindToMouse3D
* **HeldButtonZone**, _by Dougomite_ : a button activated zone for which the player needs to keep the button pressed for a certain duration to activate
* **MarbleCharacter**, _by AlexanderGheorghe_ : scripts that enable creating marble type characters. includes example character prefab
* **MMFeedbackLootDrops**, _by Dougomite_ : an MMFeedback that spawns "loot" (item pickers or any object you want) in a certain radius at weighted chances
* **MouseControls3D**, _by AlexanderGheorghe_ : a collection of extension scripts that implement Diablo-like mouse controls (double click to run, click and hold to make the character follow mouse position, click an enemy to pathfind to it and attack when in line of sight and in range). requires adding the _public float Range = 10f;_ declaration to Weapon.cs so the character knows when it is in range to attack, depending on the weapon he has equipped. includes unitypackage for easy installation and an example character prefab
* **MultiInventoryDetails**, _by men8_ : an addon to handle all active inventories on scene. See [this repo](https://github.com/men8/MultiInventoryDetails) for more info.
Expand Down

0 comments on commit b3ea4d6

Please sign in to comment.