SELF: http://blog.csdn.net/Monzart7an/article/details/24435843
Currently, there are three ideas:
1. animation key frame callback + range detection.
This is shown in an example in asset store. In fact, it was similar to this during client games, when a weapon is moved to a frame, the system adds damage to the target if there are monsters in the center of the computing weapon space. The function used for range detection is:
Physics. overlapsphere
Static function overlapsphere (position: vector3, radius: float, layermask: Int = alllayers): collider [];
Description
Returns an array with all colereers touching or inside the Sphere.
This method is sufficient for most games and has no performance overhead.
2. animation key frame callback + linear detection.
This is what we can see from the following: the idea is to select a few points on the weapon's motion track, and then perform linear detection on these points. I think this is more suitable for cutting an ax horizontally.
Http://blog.sina.com.cn/s/blog_8373d8f00101989i.html
However, I don't think it is necessary to say in the above link that the value of each frame is calculated. You can set several key frames in the animation, then record the points of the current key frame and the points of the previous key frame for ray detection. This function is used:
Physics. linecast
Static function linecast (START: vector3, end: vector3, layermask: Int = defaultraycastlayers): bool;
Description
Returns true if there is any collider intersecting the linestart
Andend
.
3. Collision body callback
Mount an empty gameobject to the weapon, then attach a collider (check the mountain istrigger) and Rigidbody to the gameobject, and then listen to the void ontriggerenter (collider other) event.
I used this demo this time. I didn't have a large-scale test, but I just made a demo. According to the Internet, this will have performance overhead and I will have a chance to test it later.
You are welcome to add.
(Transfer) collision detection of weapons and characters in Unity