Quantcast
Viewing latest article 26
Browse Latest Browse All 91

Restricting horizontal slash attack

I've been working on making this slash attack for my character. The whole point to this script is to put the damage range in sync with the slashing animation. The slash is completely horizontal and is scripted out make enemies bounce back. I have most of that but what I really need to restrict it on x axis. If I haven't explained it enough let me give you an example of what its doing. When an enemies in front of me but above the area my swing attack shouldn't be able to reach. I use my swing attack and it still does damage anyways. what I need is a way is restrict my hit detection range between two angles rolling around the x axis. I'm sorry if I didn't explain this so well just tell me if I need to make something more clear. this is the code I've come up with what I've got it doings is it applies damage it can tell if an enemy is in front of it (uses the dot product for that) it can even knock said enemy backwards void Knockback(){ Vector3 grenadeOrigin = transform.position; Collider[] colliders = Physics.OverlapSphere (grenadeOrigin, radius); foreach (Collider hit in colliders){ Rigidbody rb = hit.GetComponent(); if (rb){ Vector3 dir = (rb.transform.position - transform.position).normalized; float direction = Vector3.Dot(dir, transform.forward); Debug.Log(direction); if (direction >0.1){ rb.AddExplosionForce(power, grenadeOrigin, radius, 0); //This is where we apply force to our enemy and various other rigid bodies hit.gameObject.SendMessage("Damager", Damage, SendMessageOptions.DontRequireReceiver); //This is where we apply damage to the enemy } } } }

Viewing latest article 26
Browse Latest Browse All 91

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>