Collision detection of weapons and characters in Unity

Source: Internet
Author: User

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 linestartAndend.

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.