- Home /
Top Down RPG sword swing detection
Hello,
currently working on an top down rpg. movement, attacks, animation,.. working all really well.
But different attacks have a different attack speed. I made the hit detection with a box collider (trigger) + rigidboy (collision detection = continous) on the sword and on the player. Works really well until my attacks are too fast for the triggers =/
No i won't want the attacks to be slower ;)
Is there any alternative, detecting a swordhit? I came up to Physics.SphereCast. This is working, but I really don't know how to just to recognize the enemies in the area where the sword is swinging? Now it detects all enemys around me in the specific radius.
Has anyone did something similar? Any Solutions for it?
Thanks!
It's not a solution, but an alternative, as I'm also working on a top-down RPG and had problems with colliders and triggers on the weapons. I found it was far easier to just pretend they hit.
For instance, when the enemy knight has an attack that I've labeled as "forward", it plays the animation I choose, and sends out a ray in the forward direction of the knight, the distance of which is also put in a variable. Since the knight is always "lookAt" player, the player should be right in front of him, and if close enough (the distance variable), the ray will hit, and I can do all my damage math.
This works well also because I want to have a "dodge" chance, a small chance -- increasing if the Player speed > Enemy Accuracy -- for the player ot not get damage done. Can't do that with physics.
I'm actually working on this right now, and plan on releasing an asset store package with all of this.
I'm designing it in such a way that the game builder need only list a couple variables for each weapon, attach the weapon to an enemy prefab, and all the rest is automatically done. That way it's super easy to create new enemies, super easy to create new attacks & weapons. It works with magic too -- both projectile magic and instant-hit magic -- making it super fast to set up new magic attacks with new particles (assu$$anonymous$$g that you're like me and buy particles from the asset store).
Hopefully that idea works for you -- using alternatives to physics for your hits. Once I switched, I found everything was fairly simple and works very well.
If your enemies have rigid bodies attached I don't think setting collision detection to continuous will help. Continuous is used to improve detection against static meshes, so other collisions will be checked at regular rate. Try setting the sword detection mode to ContinuousDynamic and the enemies to continuous.
Thanks -- I'll try that out if I get back to that method. I've switched, for now, to a fake method, simply casting a ray from the enemy to the player. It's actually better, in the end, for my purpose it turns out.
If casting a ray works for you definitely stick with that: it's much faster than using continuous dynamic collision detection.
Answer by koss · Sep 27, 2013 at 04:13 PM
Thank you guys! I made a OverlapSphere and then calculated the angle between me and and the enemy.