Unity Day A technical point (vii)---to the nearest point of the bounding box

Source: Internet
Author: User

Rigidbody.closestpointonbounds to the nearest point of the bounding box
public class Example:monobehaviour {function Start () {var explosionposition = transform.position;//This script is attached to the exploded flame prefabs var colliders:collider[] = Physics.overlapsphere (explosionposition, Explosionradius);//Get the explosion point as the center, Within a certain radius of the sphere inside the Gameobect//traverse range of the object for (Var hits in colliders) {if (!hit) continue;//If this gameobject is a rigid body if (hit.rigidbody) {h It.rigidbody.AddExplosionForce (Explosionpower, Explosionposition, Explosionradius, 3.0);//give this rigid body an external var Closestpoint = Hit.rigidbody.ClosestPointOnBounds (explosionposition);//Remove the nearby object closest to the point of the explosion, the distance to the explosion point var distance = Vector3.distance (Closestpoint, explosionposition);//Calculate the distance  var hitpoints = 1.0-mathf.clamp01 (Distance/ Explosionradius);//MATHF.CLAMP01 means to force the value at 0. 1 range, if the value exceeds this range, then take upper limit or downline hitpoints *= explosiondamage; Hit.rigidbody.SendMessageUpwards ("Applydamage", hitpoints, Sendmessageoptions.dontrequirereceiver); } }}
This JS code, you can use the previous transcoding function to C # understanding Oh ~
It is suitable for the damage caused by the explosion of oil barrels and barrels. The distance is different, the damage is not the same ~

Unity Day A technical point (vii)---to the nearest point of the bounding box

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.