Skip to content
Snippets Groups Projects
Commit ff2699ba authored by Gard Aleksander Furre's avatar Gard Aleksander Furre
Browse files

made movement use moveposition and added a timer for knockback to remove speed

parent 868c3569
No related branches found
No related tags found
Loading
......@@ -88,6 +88,9 @@ namespace BigSock {
// The direction the character last moved.
protected Vector2 moveDir;
// trigger for in knockback.
protected bool inKnockBack = false;
/*
The inventory of the character.
......@@ -178,20 +181,30 @@ namespace BigSock {
MovementDir = moveDir,
};
}
/*
Using a courutine to set trigger in knockback.
*/
IEnumerator knockBackTimer()
{
inKnockBack = true;
yield return new WaitForSeconds(0.15F);
rb.velocity = Vector2.zero;
inKnockBack = false;
}
/*
Add Knockback.
Add Knockback. (used only for dash ?)
*/
public void KnockBack(float force, Vector2 difference) {
rb.AddForce(difference * force, ForceMode2D.Impulse);
StartCoroutine(knockBackTimer());
//rb.MovePosition((Vector2)transform.position + (difference * force * Time.fixedDeltaTime));
}
public void KnockBack(IAttackStats attack) {
Vector2 difference = ((Vector2) transform.position - attack.Source).normalized;
//KnockBack(attack.Knockback, difference);
rb.AddForce(difference * attack.Knockback, ForceMode2D.Impulse);
StartCoroutine(knockBackTimer());
}
/*
......@@ -199,8 +212,11 @@ namespace BigSock {
*/
protected virtual bool TryMove(Vector2 direction) {
moveDir = direction;
if(direction != Vector2.zero) {
rb.AddForce(direction * (float) MovementSpeed * Time.fixedDeltaTime, ForceMode2D.Impulse);
if(direction != Vector2.zero && !inKnockBack) {
//Using movePosition to get a "snappy" movement.
//rb.AddForce(direction * (float) MovementSpeed * Time.fixedDeltaTime, ForceMode2D.Impulse);
rb.MovePosition((Vector2)transform.position + (direction * (float) MovementSpeed * Time.fixedDeltaTime));
//rb.velocity = (direction * (float) MovementSpeed);
return true;
}
return false;
......
......@@ -13,7 +13,7 @@ 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 float BASE_FORCE = 1f;
public static readonly TimeSpan IFRAME_DURATION = new TimeSpan(0, 0, 0, 0, 500);
public override ulong Id => 201;
......
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