- Home /
Would SphereCast work for creating a detection radious larger than the one provided by Raycast?
Ok, so I finally have my melee combat system fully functional, so now I want to improve it further. One problem Im having is that Im using a Raycast to look for a target, if the target is within the attack range we send an attack notification, straightforward stuff but my issue is that you have to be looking perfectly at the enemy in order to hit him, and since my project is a third person RPG it's often somewhat hard to aim perfectly at a moving enemy, plus it's somewhat misleading since most of the attack animations have rather large swipe range.
So, Im trying to find an alternative method that would give me a range to detect the collision with an enemy other than the straight line Raycast. I've been looking into some documentation regarding SphereCast but I can't quite understand how it works, I know I can cast a sphere in any direction I want, so I guess I would be casting on on the front of my character on the overall range of where the melee weapons land, but would any object inside the sphere be "hit" by it or is it simply casting a sphere but still relies on the straight line use to place the sphere in the world?
It doesn't sound to me like Spherecast is what you are looking for. As an alternate simply check the distance between each enemy and the angle between your character forward and the enemy. No raycast necessary. If the enemy is within a specified distance and within a specified angle, it is a hit.
Answer by AlejandroGorgal · Dec 02, 2013 at 10:31 PM
Ok, in the remote case that somebody else out there is developing a melee system that's more accurate than the normal Raycast method I found an alternative that works very well:
http://forum.unity3d.com/threads/58574-Nice-little-melee-system-I-created-with-triggers
Basically, you add a collider to the melee weapon and use it to send the damage notifications when they enter in contact with the enemy, so it's extremely accurate.
Your answer
Follow this Question
Related Questions
Top Down RPG sword swing detection 1 Answer
Ai Zombie Melee Attack script. 5 Answers
NullReferenceException: Object reference not set to an instance of an object Raycast...? 1 Answer
Brawl style melee combat? 0 Answers
Tag set by animation: problem 0 Answers