Skip to content
Snippets Groups Projects

Dodge

Merged Robin Halseth Sandvik requested to merge master into main
6 files
+ 297
34
Compare changes
  • Side-by-side
  • Inline
Files
6
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using BigSock.Service;
namespace BigSock {
/*
A basic dodge move that gives a push and a short invincibility.
*/
public class AbilityDodge : BaseAbility {
public static readonly float BASE_FORCE = 0.5f;
public static readonly TimeSpan IFRAME_DURATION = new TimeSpan(0, 0, 0, 0, 500);
public override ulong Id => 201;
public override string Name => "Dodge";
public override string Description => "A basic dodge move.";
public AbilityDodge() {
StaminaCost = 4;
Cooldown = new TimeSpan(0, 0, 0, 1, 0);
}
/*
Activates the ability.
*/
protected override bool Activate(Character actor, Vector3? target) {
if(target == null) return false;
// Get direction.
var temp = (target.Value - actor.transform.position);
temp.z = 0;
var direction = (Vector2) temp.normalized;
// Get the force.
var force = BASE_FORCE * actor.Stats.MoveSpeed;
// Apply the push and iframes.
actor.KnockBack(force, direction);
actor.AddStatusEffect(StatusEffectType.Invincible, IFRAME_DURATION);
return true;
}
}
}
\ No newline at end of file
Loading