1
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using UnityEngine;
|
||||
using Lightbug.CharacterControllerPro.Core;
|
||||
using Lightbug.Utilities;
|
||||
|
||||
namespace Lightbug.CharacterControllerPro.Demo
|
||||
{
|
||||
|
||||
public class JumpPad : CharacterDetector
|
||||
{
|
||||
public bool useLocalSpace = true;
|
||||
public Vector3 direction = Vector3.up;
|
||||
public float jumpPadVelocity = 10f;
|
||||
|
||||
protected override void ProcessEnterAction(CharacterActor characterActor)
|
||||
{
|
||||
if (characterActor.GroundObject != gameObject)
|
||||
return;
|
||||
|
||||
characterActor.ForceNotGrounded();
|
||||
|
||||
Vector3 direction = useLocalSpace ? transform.TransformDirection(this.direction) : this.direction;
|
||||
characterActor.Velocity += direction * jumpPadVelocity;
|
||||
}
|
||||
|
||||
protected override void ProcessStayAction(CharacterActor characterActor)
|
||||
{
|
||||
ProcessEnterAction(characterActor);
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
Vector3 direction = useLocalSpace ? transform.TransformDirection(this.direction) : this.direction;
|
||||
//Gizmos.DrawRay(transform.position, direction * 2f);
|
||||
CustomUtilities.DrawArrowGizmo(transform.position, transform.position + direction * 2f, Color.red);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,131 @@
|
||||
using UnityEngine;
|
||||
using Lightbug.CharacterControllerPro.Core;
|
||||
using Lightbug.Utilities;
|
||||
|
||||
namespace Lightbug.CharacterControllerPro.Demo
|
||||
{
|
||||
|
||||
public class PositionAndRotationModifier : CharacterDetector
|
||||
{
|
||||
public enum CallbackType
|
||||
{
|
||||
Enter,
|
||||
Exit
|
||||
}
|
||||
|
||||
[Header("Callbacks")]
|
||||
public CallbackType callbackType = CallbackType.Enter;
|
||||
|
||||
[Header("Position")]
|
||||
|
||||
public bool teleport = false;
|
||||
|
||||
[Condition("teleport", ConditionAttribute.ConditionType.IsTrue, ConditionAttribute.VisibilityType.NotEditable)]
|
||||
public Transform teleportTarget = null;
|
||||
|
||||
[Header("Rotation")]
|
||||
|
||||
public bool rotate = false;
|
||||
|
||||
[Condition("rotate", ConditionAttribute.ConditionType.IsTrue, ConditionAttribute.VisibilityType.Hidden)]
|
||||
public RotationMode rotationMode = RotationMode.ModifyUp;
|
||||
|
||||
[Condition("rotationMode", ConditionAttribute.ConditionType.IsEqualTo, ConditionAttribute.VisibilityType.Hidden, (int)RotationMode.ModifyUp)]
|
||||
[Tooltip("The target Transform.up vector to use.")]
|
||||
public Transform referenceTransform = null;
|
||||
|
||||
[Condition(
|
||||
new string[] { "rotationMode", "rotate" },
|
||||
new ConditionAttribute.ConditionType[] { ConditionAttribute.ConditionType.IsEqualTo, ConditionAttribute.ConditionType.IsTrue },
|
||||
new float[] { (int)RotationMode.AlignWithObject, 0f },
|
||||
ConditionAttribute.VisibilityType.Hidden)]
|
||||
[Tooltip("The target transform to use as the reference.")]
|
||||
public Transform verticalAlignmentReference = null;
|
||||
|
||||
[Condition(
|
||||
new string[] { "rotationMode", "rotate" },
|
||||
new ConditionAttribute.ConditionType[] { ConditionAttribute.ConditionType.IsEqualTo, ConditionAttribute.ConditionType.IsTrue },
|
||||
new float[] { (int)RotationMode.AlignWithObject, 0f },
|
||||
ConditionAttribute.VisibilityType.Hidden)]
|
||||
public VerticalAlignmentSettings.VerticalReferenceMode upDirectionReferenceMode = VerticalAlignmentSettings.VerticalReferenceMode.Away;
|
||||
|
||||
|
||||
public enum RotationMode
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
ModifyUp,
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
AlignWithObject
|
||||
}
|
||||
|
||||
void Teleport(CharacterActor characterActor)
|
||||
{
|
||||
if (!teleport)
|
||||
return;
|
||||
|
||||
if (teleportTarget == null)
|
||||
return;
|
||||
|
||||
Vector3 targetPosition = teleportTarget.position;
|
||||
|
||||
// If the character is 2D, don't change the position z component (Transform).
|
||||
if (characterActor.Is2D)
|
||||
targetPosition.z = characterActor.transform.position.z;
|
||||
|
||||
characterActor.Teleport(targetPosition);
|
||||
}
|
||||
|
||||
void Rotate(CharacterActor characterActor)
|
||||
{
|
||||
if (!rotate)
|
||||
return;
|
||||
|
||||
switch (rotationMode)
|
||||
{
|
||||
case RotationMode.ModifyUp:
|
||||
|
||||
if (referenceTransform != null)
|
||||
characterActor.Up = referenceTransform.up;
|
||||
|
||||
if (characterActor.constraintRotation)
|
||||
{
|
||||
characterActor.upDirectionReference = null;
|
||||
characterActor.constraintUpDirection = characterActor.Up;
|
||||
}
|
||||
|
||||
break;
|
||||
case RotationMode.AlignWithObject:
|
||||
|
||||
// Just in case the rotation constraint is active ...
|
||||
characterActor.constraintRotation = true;
|
||||
characterActor.upDirectionReference = verticalAlignmentReference;
|
||||
characterActor.upDirectionReferenceMode = upDirectionReferenceMode;
|
||||
characterActor.constraintUpDirection = characterActor.Up;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ProcessEnterAction(CharacterActor characterActor)
|
||||
{
|
||||
if (callbackType != CallbackType.Enter)
|
||||
return;
|
||||
|
||||
Teleport(characterActor);
|
||||
Rotate(characterActor);
|
||||
}
|
||||
|
||||
protected override void ProcessExitAction(CharacterActor characterActor)
|
||||
{
|
||||
if (callbackType != CallbackType.Exit)
|
||||
return;
|
||||
|
||||
Teleport(characterActor);
|
||||
Rotate(characterActor);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user