- Home /
I need help deciding the best way to pass different vector values to my hit-boxes and hit-forces depending on which attack is being used !! please help
I have an Attack Manager script that runs the characters animations for each attack, If possible I wanted to store the different vector values in my Attack Manager script and pass the values off to my individual hitboxes of which we have 10 (because of how the spine engine works with unity). Basically, I want the mutable variable/etc to be then used in the corresponding Hitbox script and the vector and force change depending on the animation/attack being used.
This is what I have set up so far in the Attack Manager... there are more attacks but all run on a similar base so didn't want to show too much code. * this is where I was thinking of setting up the vectors and forces. public class NinjaAttackManager : MonoBehaviour { SkeletonAnimation skeletonAnimation; [SerializeField] Rigidbody2D ninjaRigidbody;
private float spAttCounter = 0f;
[SerializeField] float specialAttackTime = 2f;
private bool chargingStabCheck = false;
private bool chargingStabUpCheck = false;
private bool chargingStabDownCheck = false;
private bool chargingSlashCheck = false;
private bool chargingSlashUpCheck = false;
private bool chargingSlashDownCheck = false;
[SerializeField] KeyCode upControl;
[SerializeField] KeyCode downControl;
[SerializeField] KeyCode rightControl;
[SerializeField] KeyCode leftControl;
[SerializeField] KeyCode stabControl;
[SerializeField] KeyCode slashControl;
private Vector2 stabDirection0;
private Vector2 stabDirection1;
private Vector2 stabDirection2;
private Vector2 backStabDirection0;
private Vector2 backStabDirection1;
private Vector2 slashDirection0;
private Vector2 slashDirection1;
private Vector2 slashDirection2;
private Vector2 backSlashDirection0;
private Vector2 backSlashDirection1;
void Start()
{
skeletonAnimation = GetComponent<SkeletonAnimation>();
}
// Update is called once per frame
void FixedUpdate()
{
Slashes();
SpecialSlashOver();
SpecialSlashUp();
SpecialSlashDown();
Stabs();
SpecialStabOver();
SpecialStabUp();
SpecialStabDown();
}
private void Slashes()
{
if (Input.GetKeyDown(slashControl))
{
if (Input.GetKeyDown(rightControl) || Input.GetKeyDown(leftControl) || Input.GetKeyDown(upControl) || Input.GetKeyDown(downControl))
{
return;
}
else
{
slashDirection0 = new Vector2(5f, 5f);
slashDirection1 = new Vector2(7f, 7f);
slashDirection2 = new Vector2(10f, 10f);
backSlashDirection0 = new Vector2(1f, 1f);
backSlashDirection1 = new Vector2(2f, 2f);
skeletonAnimation.state.SetAnimation(2, "Slash", false);
}
}
if (Input.GetKeyDown(slashControl) && Input.GetKey(upControl))
{
slashDirection0 = new Vector2(5f, 5f);
slashDirection1 = new Vector2(7f, 7f);
slashDirection2 = new Vector2(10f, 10f);
backSlashDirection0 = new Vector2(1f, 1f);
backSlashDirection1 = new Vector2(2f, 2f);
skeletonAnimation.state.SetAnimation(2, "UpSlash", false);
}
if (Input.GetKeyDown(slashControl) && Input.GetAxis("Horizontal") > 0 || Input.GetKeyDown("x") && Input.GetAxis("Horizontal") < 0)
{
slashDirection0 = new Vector2(5f, 5f);
slashDirection1 = new Vector2(7f, 7f);
slashDirection2 = new Vector2(10f, 10f);
backSlashDirection0 = new Vector2(1f, 1f);
backSlashDirection1 = new Vector2(2f, 2f);
skeletonAnimation.state.SetAnimation(2, "OverSlash", false);
}
if (Input.GetKeyDown(slashControl) && Input.GetKey(downControl))
{
slashDirection0 = new Vector2(5f, 5f);
slashDirection1 = new Vector2(7f, 7f);
slashDirection2 = new Vector2(10f, 10f);
backSlashDirection0 = new Vector2(1f, 1f);
backSlashDirection1 = new Vector2(2f, 2f);
skeletonAnimation.state.SetAnimation(2, "DownSlash", false);
}
}
this is one of the Hitbox examples which all are basically identical just set that way for the individual trigger collisions for each collider. public class NinjaSlashHitbox0 : MonoBehaviour { //[SerializeField] Vector2 slashDirection; //[SerializeField] float slashForce = 50f;
BoundingBoxFollower follower;
[SerializeField] Transform myParentsObject;
// Start is called before the first frame update
void Start()
{
follower = GetComponent<BoundingBoxFollower>();
}
private void FixedUpdate()
{
//FlipForceDirection();
}
private void OnTriggerEnter2D(Collider2D otherObject)
{
if (otherObject.GetComponentInParent<Rigidbody2D>() == myParentsObject.GetComponentInParent<Rigidbody2D>())
{
Debug.Log("I Hit Myself");
}
else if (otherObject.GetComponentInParent<Rigidbody2D>())
{
otherObject.GetComponentInParent<Rigidbody2D>().AddForce(slashDirection * slashForce);
}
}
Please, any advice tips or tricks would be very much appreciated! ps. I'm just self-taught over the last year on and off so if my code is garbage I apologize.. Also, I just noticed some small changes that I was making to it that I didn't update it all yet, incase you notice the inconsistency..
Also, I should add that the Attack $$anonymous$$anager script is attached to the Parent game object then the hitboxes are all children to the game object with each hitbox having its own game object and corresponding script.
Your answer