Skip to content
Snippets Groups Projects
Commit 9d50f2d9 authored by Matthewit Dechatech's avatar Matthewit Dechatech
Browse files

Fix crushing, flame shield rotation, add smooth camera rotation

parent 7a76e854
No related branches found
No related tags found
No related merge requests found
Showing
with 284 additions and 39 deletions
Loading
Loading
@@ -125,6 +125,8 @@ MonoBehaviour:
ActiveTrigger:
ActiveBool:
AvailableBool:
DestroyInWater: 0
RotateToGravity: 1
--- !u!212 &21273226
SpriteRenderer:
m_ObjectHideFlags: 1
Loading
Loading
@@ -170,6 +172,10 @@ Prefab:
propertyPath: Animator
value:
objectReference: {fileID: 9554564}
- target: {fileID: 0}
propertyPath: RotateToGravity
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 132248}
Loading
Loading
Loading
Loading
@@ -125,6 +125,8 @@ MonoBehaviour:
ActiveTrigger:
ActiveBool:
AvailableBool:
DestroyInWater: 0
RotateToGravity: 1
--- !u!212 &21245918
SpriteRenderer:
m_ObjectHideFlags: 1
Loading
Loading
@@ -157,7 +159,11 @@ Prefab:
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_Modifications:
- target: {fileID: 0}
propertyPath: RotateToGravity
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 177786}
Loading
Loading
Loading
Loading
@@ -181,6 +181,7 @@ MonoBehaviour:
ActiveBool:
AvailableBool:
DestroyInWater: 0
RotateToGravity: 1
--- !u!212 &21204532
SpriteRenderer:
m_ObjectHideFlags: 1
Loading
Loading
@@ -226,6 +227,10 @@ Prefab:
propertyPath: GiveAir
value: 1
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: RotateToGravity
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 196572}
Loading
Loading
Loading
Loading
@@ -191,6 +191,7 @@ MonoBehaviour:
ActiveBool:
AvailableBool:
DestroyInWater: 1
RotateToGravity: 1
--- !u!212 &21234764
SpriteRenderer:
m_ObjectHideFlags: 1
Loading
Loading
@@ -232,6 +233,10 @@ Prefab:
propertyPath: DestroyInWater
value: 1
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: RotateToGravity
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 131022}
Loading
Loading
Loading
Loading
@@ -156,6 +156,7 @@ MonoBehaviour:
ActiveBool:
AvailableBool:
DestroyInWater: 1
RotateToGravity: 1
--- !u!114 &11484702
MonoBehaviour:
m_ObjectHideFlags: 1
Loading
Loading
@@ -283,6 +284,10 @@ Prefab:
propertyPath: DestroyInWater
value: 1
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: RotateToGravity
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 148158}
Loading
Loading
Loading
Loading
@@ -93,6 +93,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
Target: {fileID: 0}
RotateToGravity: 1
RotationSmoothness: .200000003
PixelPerfect: 1
SnapOnInit: 1
CurrentState: 0
Loading
Loading
@@ -149,6 +150,10 @@ Prefab:
propertyPath: PixelPerfect
value: 1
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: RotationSmoothness
value: .200000003
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 175064}
Loading
Loading
Loading
Loading
@@ -93,6 +93,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
Target: {fileID: 0}
RotateToGravity: 1
RotationSmoothness: .200000003
PixelPerfect: 1
SnapOnInit: 1
CurrentState: 0
Loading
Loading
@@ -141,6 +142,10 @@ Prefab:
propertyPath: PixelPerfect
value: 1
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: RotationSmoothness
value: .200000003
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 144678}
Loading
Loading
Loading
Loading
@@ -93,6 +93,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
Target: {fileID: 0}
RotateToGravity: 1
RotationSmoothness: .200000003
PixelPerfect: 1
SnapOnInit: 1
CurrentState: 0
Loading
Loading
@@ -145,6 +146,10 @@ Prefab:
propertyPath: PixelPerfect
value: 1
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: RotationSmoothness
value: .200000003
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 198666}
Loading
Loading
Loading
Loading
@@ -583,11 +583,11 @@ Prefab:
m_Modifications:
- target: {fileID: 412156, guid: 0a0977eefd4ac134292bf62307ed7b1c, type: 2}
propertyPath: m_LocalPosition.x
value: 38.7000008
value: 38.3199997
objectReference: {fileID: 0}
- target: {fileID: 412156, guid: 0a0977eefd4ac134292bf62307ed7b1c, type: 2}
propertyPath: m_LocalPosition.y
value: 3.25999999
value: 2.58200002
objectReference: {fileID: 0}
- target: {fileID: 412156, guid: 0a0977eefd4ac134292bf62307ed7b1c, type: 2}
propertyPath: m_LocalPosition.z
Loading
Loading
@@ -19581,11 +19581,11 @@ Prefab:
m_Modifications:
- target: {fileID: 424606, guid: dbca39c759708bb4dbdc512f0b2a13b2, type: 2}
propertyPath: m_LocalPosition.x
value: 63.9700012
value: 38.8400002
objectReference: {fileID: 0}
- target: {fileID: 424606, guid: dbca39c759708bb4dbdc512f0b2a13b2, type: 2}
propertyPath: m_LocalPosition.y
value: -.889999986
value: 2.22000003
objectReference: {fileID: 0}
- target: {fileID: 424606, guid: dbca39c759708bb4dbdc512f0b2a13b2, type: 2}
propertyPath: m_LocalPosition.z
Loading
Loading
@@ -28434,6 +28434,151 @@ Transform:
- {fileID: 1495252013}
m_Father: {fileID: 1139116792}
m_RootOrder: 108
--- !u!1 &1999524540 stripped
GameObject:
m_PrefabParentObject: {fileID: 105462, guid: 0a0977eefd4ac134292bf62307ed7b1c, type: 2}
m_PrefabInternal: {fileID: 54808512}
--- !u!114 &1999524541
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1999524540}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 38d15c77fb15ac14d80922d10c1c0a37, type: 3}
m_Name:
m_EditorClassIdentifier:
ObjectTrigger: {fileID: 1999524542}
Animator: {fileID: 0}
--- !u!114 &1999524542
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1999524540}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3049f730761aaaf4d962d6508f24b499, type: 3}
m_Name:
m_EditorClassIdentifier:
TriggerFromChildren: 1
OnEnter:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.TriggerEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnStay:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.TriggerEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnExit:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.TriggerEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
Collisions: []
AllowReactivation: 1
OnActivateEnter:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.ObjectEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnActivateStay:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.ObjectEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnActivateExit:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.ObjectEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
Activated: 0
Animator: {fileID: 0}
ActivatedTrigger:
ActivatedBool:
--- !u!114 &1999524543
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1999524540}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 876002e17ada518448f5eabb688526bd, type: 3}
m_Name:
m_EditorClassIdentifier:
ObjectTrigger: {fileID: 0}
Animator: {fileID: 0}
PlatformTrigger: {fileID: 0}
CollidingTrigger:
CollidingBool:
SurfaceTrigger:
SurfaceBool:
CrushHorizontally: 1
HorizontalTolerance: 0
CrushVertically: 1
VerticalTolerance: .5
--- !u!114 &1999524544
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1999524540}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 90b4c07f75e2a40449585367aa1bb30c, type: 3}
m_Name:
m_EditorClassIdentifier:
TriggerFromChildren: 1
OnEnter:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.TriggerEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnStay:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.TriggerEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnExit:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.TriggerEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
AlwaysCollide: 0
OnSurfaceEnter:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.PlatformSurfaceEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnSurfaceStay:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.PlatformSurfaceEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnSurfaceExit:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.PlatformSurfaceEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnPlatformEnter:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.PlatformCollisionEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnPlatformStay:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.PlatformCollisionEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
OnPlatformExit:
m_PersistentCalls:
m_Calls: []
m_TypeName: Hedgehog.Core.Triggers.PlatformCollisionEvent, Assembly-CSharp, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!1001 &1999638147
Prefab:
m_ObjectHideFlags: 0
Loading
Loading
@@ -1204,26 +1204,27 @@ private bool GroundCeilingCheck()
var rightCheck = this.TerrainCast(Sensors.CenterRight.position, Sensors.TopRight.position,
ControllerSide.Right);
 
LeftCeilingHit = leftCheck;
LeftCeiling = LeftCeilingHit ? leftCheck.Transform : null;
RightCeilingHit = rightCheck;
RightCeiling = RightCeilingHit ? rightCheck.Transform : null;
// There is nothing to do here but set variables. This information is used for crushers.
if (leftCheck)
{
LeftCeilingHit = leftCheck;
LeftCeiling = leftCheck.Transform;
}
 
if (rightCheck)
{
RightCeilingHit = rightCheck;
RightCeiling = rightCheck.Transform;
}
if (leftCheck)
{
NotifyTriggers(leftCheck);
IgnoreNextCollision = false;
return true;
}
if (rightCheck)
{
RightCeilingHit = rightCheck;
RightCeiling = rightCheck.Transform;
NotifyTriggers(rightCheck);
IgnoreNextCollision = false;
return true;
Loading
Loading
Loading
Loading
@@ -14,11 +14,6 @@ public class FlameSpecial : DoubleJump
[Tooltip("The velocity of the dash, in units per second.")]
public Vector2 DashVelocity;
 
/// <summary>
/// Keeps track of whether we need to flip the sprite when performing the dash.
/// </summary>
private bool _flipped;
public override void Reset()
{
base.Reset();
Loading
Loading
@@ -37,21 +32,10 @@ public override void OnActiveEnter()
 
End();
 
// Store whether or not we flipped the sprite so we can flip back later
_flipped = !Controller.FacingForward;
if (_flipped)
transform.localScale -= new Vector3(transform.localScale.x * 2.0f, 0.0f);
// Going to flip the sprite back when we land
Controller.OnAttach.AddListener(OnAttach);
}
public void OnAttach()
{
// If we flipped during the dash then flip the sprite back
if (_flipped)
transform.localScale -= new Vector3(transform.localScale.x * 2.0f, 0.0f);
Controller.OnAttach.RemoveListener(OnAttach);
// Flip the shield based on which way we're facing
if ((!Controller.FacingForward && transform.localScale.x > 0.0f) ||
(Controller.FacingForward && transform.localScale.x < 0.0f))
transform.localScale -= new Vector3(transform.localScale.x*2.0f, 0.0f);
}
}
}
Loading
Loading
@@ -14,6 +14,12 @@ public class Shield : Move
[Tooltip("Whether to destroy the powerup when underwater.")]
public bool DestroyInWater;
 
/// <summary>
/// Whether to rotate the shield with the direction of gravity.
/// </summary>
[Tooltip("Whether to rotate the shield with the direction of gravity.")]
public bool RotateToGravity;
public override MoveGroup[] Groups
{
get { return new[] {MoveGroup.Shield}; }
Loading
Loading
@@ -47,6 +53,8 @@ public override void OnManagerAdd()
{
Controller.OnReactiveEnter.AddListener(OnReactiveEnter);
}
Perform(true);
}
 
public override void OnManagerRemove()
Loading
Loading
@@ -65,5 +73,14 @@ public void OnReactiveEnter(BaseReactive reactive)
if (DestroyInWater && Controller.Inside<Water>())
Destroy(gameObject);
}
public override void OnActiveUpdate()
{
if (RotateToGravity)
transform.eulerAngles = new Vector3(
transform.eulerAngles.x,
transform.eulerAngles.y,
Controller.GravityDirection + 90.0f);
}
}
}
Loading
Loading
@@ -24,6 +24,19 @@ public class HedgehogCameraController : MonoBehaviour
[Tooltip("Whether to rotate the camera based on the controller's direction of gravity.")]
public bool RotateToGravity;
 
/// <summary>
/// How smoothly the rotation occurs, 1 being smoothest and 0 being instant.
/// </summary>
[Range(0.0f, 1.0f)]
[Tooltip("How smoothly the rotation occurs, 1 being smoothest and 0 being instant.")]
public float RotationSmoothness;
public float Rotation
{
get { return transform.eulerAngles.z; }
set { transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, value); }
}
/// <summary>
/// Whether to round position to the nearest pixel (0.01 unit).
/// </summary>
Loading
Loading
@@ -173,6 +186,7 @@ public void Reset()
{
Target = FindObjectOfType<HedgehogController>();
RotateToGravity = true;
RotationSmoothness = 0.2f;
PixelPerfect = true;
SnapOnInit = false;
 
Loading
Loading
@@ -232,7 +246,22 @@ public void FixedUpdate()
CheckChangeTarget();
HandleState();
 
if(RotateToGravity) Rotate(Target.GravityDirection + 90.0f);
if (RotateToGravity)
{
if (DMath.Equalsf(RotationSmoothness))
{
Rotate(Target.GravityDirection + 90.0f);
}
else
{
Rotate(Mathf.LerpAngle(Rotation, Target.GravityDirection + 90.0f,
Time.fixedDeltaTime * (1.0f / RotationSmoothness)));
}
}
else
{
Rotate(0.0f);
}
 
_previousTargetPosition = Target.transform.position;
 
Loading
Loading
Loading
Loading
@@ -31,6 +31,12 @@ public class Crusher : ReactivePlatform
[Tooltip("Whether to activate when being crushed on the ground and ceiling.")]
public bool CrushVertically;
 
/// <summary>
/// The fraction of the sensor test is checked each frame. This allows the crusher to work only
/// if the object is moving down.
/// </summary>
private float _previousVerticalFraction;
/// <summary>
/// How much to allow grounds and ceilings to touch before crushing.
/// </summary>
Loading
Loading
@@ -50,6 +56,12 @@ public override void Reset()
VerticalTolerance = 0.5f;
}
 
public override void Awake()
{
base.Awake();
_previousVerticalFraction = 1.0f;
}
/// <summary>
/// Test used to see if a controller should be crushed.
/// </summary>
Loading
Loading
@@ -69,14 +81,29 @@ public bool CheckCrush(HedgehogController controller)
/// <returns></returns>
public bool CheckVertical(HedgehogController controller)
{
if (!controller.Grounded)
if (!controller.Grounded || controller.LeftCeilingHit == null || controller.RightCeilingHit == null)
{
_previousVerticalFraction = 1.0f;
return false;
}
var averageFraction = (controller.LeftCeilingHit.Hit.fraction + controller.RightCeilingHit.Hit.fraction)/
2.0f;
// If fraction is 1, the controller only started hitting the ceiling this frame, so excuse fraction checks
if (_previousVerticalFraction == 1.0f) _previousVerticalFraction = averageFraction;
// Check for fractions vs tolerances
var result = controller.LeftCeilingHit.Hit.fraction <= 1.0f - VerticalTolerance &&
controller.RightCeilingHit.Hit.fraction <= 1.0f - VerticalTolerance;
// The average fraction must also be less than the one last frame - this makes the check false
// if the object away or stood still
result &= (DMath.Equalsf(averageFraction) || averageFraction < _previousVerticalFraction - DMath.Epsilon);
 
return (controller.LeftCeiling != null &&
controller.LeftCeilingHit.Hit.fraction <= 1.0f - VerticalTolerance) &&
_previousVerticalFraction = averageFraction;
 
(controller.RightCeiling != null &&
controller.RightCeilingHit.Hit.fraction <= 1.0f - VerticalTolerance);
return result;
}
 
/// <summary>
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment