Skip to content

Instantly share code, notes, and snippets.

@beardordie
Last active February 20, 2020 14:17
Show Gist options
  • Save beardordie/762ae54bd89ad56e98cb3c9f076d62de to your computer and use it in GitHub Desktop.
Save beardordie/762ae54bd89ad56e98cb3c9f076d62de to your computer and use it in GitHub Desktop.
Corgi Engine custom extension to the Jetpack ability that fixes three bugs with the built-in version. Tested with version 6.1. Usage: remove or disable the CharacterJetpack component and replace it with this
using MoreMountains.Tools;
using UnityEngine;
namespace MoreMountains.CorgiEngine
{
/// <summary>
/// Add this component to a character and it'll be able to jetpack
/// NOTE: This custom extended version doesn't perform a horizontal flip of the jetpack emission point
/// because that flip already happens on the parent for some PlayableCharacter prefabs
/// NOTE: It also prevents a bug in v6.1 that causes Jetpack refuel sounds and particles to play
/// at the start of the game
/// NOTE: It also prevents a bug where JetpackStop method was calling TurnJetpackElementsOff even while crouched
/// NOTE: It also triggers a MMGameEvent when jetpack is refueled to allow more customization of that event
/// Animator parameters : Jetpacking (bool)
/// </summary>
[AddComponentMenu("Corgi Engine/Character/Abilities/Character Jetpack (No Flip)")]
public class CharacterJetpackNoFlip : CharacterJetpack
{
public bool dontFlipParticleSystem = true;
// Fixes a bug with CharacterJetpack.cs in version 6.1 that has this initially set to true,
// which causes the TurnJetpackElementsOff() method to execute at the start of the game
// which is bad if you have sounds or particles set for when jetpacking is stopped or refueled
protected override void Initialization()
{
base.Initialization();
_jetpacking = false;
}
// Fixes a bug with the position of the jetpack particles. No flip is necessary because the model flips itself.
public override void Flip()
{
if (dontFlipParticleSystem)
{
if (_character == null)
{
Initialization();
}
}
else
{
base.Flip();
}
}
// Fixes a bug where JetpackStop was firing TurnJetpackElementsOff even if crouched upon release of jetpack button
public override void JetpackStop()
{
if ((!AbilityPermitted) // if the ability is not permitted
|| (_movement.CurrentState == CharacterStates.MovementStates.Gripping) // or if we're in the gripping state
|| (_movement.CurrentState == CharacterStates.MovementStates.LedgeHanging) // or if we're in the ledge hanging state
|| (_movement.CurrentState == CharacterStates.MovementStates.Crawling) // or if we're crawling
|| (_movement.CurrentState == CharacterStates.MovementStates.Crouching) // or if we're crouching
|| (_condition.CurrentState != CharacterStates.CharacterConditions.Normal)) // or if we're not in normal conditions
return;
TurnJetpackElementsOff();
// we set our current state to the previous recorded one
_movement.RestorePreviousState();
}
// Triggers a MMGameEvent when jetpack is refueled to allow more customization of that event
protected override void PlayJetpackRefueledSfx()
{
base.PlayJetpackRefueledSfx();
MMEventManager.TriggerEvent(new MMGameEvent("JetpackRefueled"));
}
[ContextMenu("Assign Particle System")]
protected virtual void AssignParticleSystem()
{
ParticleEmitter = GetComponentInChildren<ParticleSystem>();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment