Skip to content
Snippets Groups Projects
Commit 82653d92 authored by Robin Halseth Sandvik's avatar Robin Halseth Sandvik
Browse files

Reworked projectiles.

- Uses AttackStats passed from the attack.
- Takes target from attack instead of mouse pos.
- Implemented range.
parent acc7297f
No related branches found
No related tags found
1 merge request!25Ability rework.
......@@ -4,29 +4,44 @@ using UnityEngine;
using UnityEngine.InputSystem;
using static UnityEngine.GraphicsBuffer;
using BigSock.Service;
namespace BigSock {
public class AttackMovement : MonoBehaviour
{
public float speed = 10.0f;
bool moved = false;
Vector3 direction;
//Vector3 direction;
Vector3 startingPos;
/*
Damage of the character.
*/
public float Damage => baseDamage;
public float baseDamage = 1;
//public float Damage => baseDamage;
//public float baseDamage = 1;
public float KnockbackForce => knockbackForce;
public float knockbackForce = 1;
//public float KnockbackForce => knockbackForce;
//public float knockbackForce = 1;
/*
The character that activated the attack.
*/
public Character Actor { get; set; }
//public Character Actor { get; set; }
/*
The attack stats of the attack.
*/
public AttackStats Stats { get; set; }
/*
The direction of the attack.
*/
public Vector3 Direction { get; set; }
// Start is called before the first frame update
// Start is called before the first frame update
void Start()
{
}
......@@ -36,18 +51,26 @@ namespace BigSock {
{
if (!moved)
{
var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var pos = transform.position;
var temp = (mouse - pos);
temp.z = 0;
direction = temp.normalized;
//var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//var pos = transform.position;
//var temp = (mouse - pos);
//temp.z = 0;
//direction = temp.normalized;
//print($"[AttackMovement.Update()] {mouse} - {pos} = {direction}");
startingPos = transform.position;
moved = true;
}
//transform.Translate(new Vector3(1 * horizontalInput, 1 * verticalInput, 0) * speed * Time.deltaTime);
transform.Translate(direction * speed * Time.deltaTime);
transform.Translate(Direction * Stats.ProjectileSpeed * Time.deltaTime);
var traveled = Vector2.Distance(transform.position, startingPos);
// If we traveled passed our range: destroy this obj.
if(traveled > Stats.Range) {
PrefabService.SINGLETON.Destroy(gameObject);
}
}
......@@ -58,23 +81,24 @@ namespace BigSock {
if(target != null) {
var attack = new AttackStats{
Damage = Damage,
Knockback = KnockbackForce,
//Range = 0,
//AttackSpeed = AttackSpeed,
Source = transform.position,
Actor = Actor,
};
//var attack = new AttackStats{
// Damage = Damage,
// Knockback = KnockbackForce,
// //Range = 0,
// //AttackSpeed = AttackSpeed,
// Source = transform.position,
// Actor = Actor,
//};
Stats.Source = transform.position;
// If we have an actor: Apply their stat mods & trigger their OnHit.
if(Actor != null) {
attack.Damage *= Actor.Damage;
attack.Knockback *= Actor.KnockbackForce;
//Actor.TargetHit(target, attack);
}
//if(Actor != null) {
// attack.Damage *= Actor.Damage;
// attack.Knockback *= Actor.KnockbackForce;
// //Actor.TargetHit(target, attack);
//}
if(target.TakeDamage(attack)) {
if(target.TakeDamage(Stats)) {
}
}
......
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