first commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace OTGIntegrated.Abilities
|
||||
{
|
||||
public sealed class BlinkEffect : AbilityEffect
|
||||
{
|
||||
public LayerMask obstacleMask = ~0;
|
||||
public float collisionRadius = 0.45f;
|
||||
|
||||
public override void Activate(AbilityContext context)
|
||||
{
|
||||
if (context.Caster == null)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 origin = context.Caster.position + Vector3.up * 0.8f;
|
||||
Vector3 direction = context.Forward;
|
||||
float distance = Mathf.Max(0f, context.Ability.range);
|
||||
|
||||
if (Physics.SphereCast(origin, collisionRadius, direction, out RaycastHit hit, distance, obstacleMask, QueryTriggerInteraction.Ignore))
|
||||
{
|
||||
distance = Mathf.Max(0f, hit.distance - collisionRadius);
|
||||
}
|
||||
|
||||
Vector3 target = context.Caster.position + direction * distance;
|
||||
CharacterController controller = context.Caster.GetComponent<CharacterController>();
|
||||
if (controller != null)
|
||||
{
|
||||
controller.enabled = false;
|
||||
context.Caster.position = target;
|
||||
controller.enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Caster.position = target;
|
||||
}
|
||||
|
||||
Destroy(gameObject, 0.15f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user