Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity rb.addexplosionforce 2d

using UnityEngine;

public static class Rigidbody2DExt {

    public static void AddExplosionForce(this Rigidbody2D rb, float explosionForce, Vector2 explosionPosition, float explosionRadius, float upwardsModifier = 0.0F, ForceMode2D mode = ForceMode2D.Force) {
        var explosionDir = rb.position - explosionPosition;
        var explosionDistance = explosionDir.magnitude;

        // Normalize without computing magnitude again
        if (upwardsModifier == 0)
            explosionDir /= explosionDistance;
        else {
            // From Rigidbody.AddExplosionForce doc:
            // If you pass a non-zero value for the upwardsModifier parameter, the direction
            // will be modified by subtracting that value from the Y component of the centre point.
            explosionDir.y += upwardsModifier;
            explosionDir.Normalize();
        }

        rb.AddForce(Mathf.Lerp(0, explosionForce, (1 - explosionDistance)) * explosionDir, mode);
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: convert list string to list enum c# 
Csharp :: c# list remove by index 
Csharp :: div element position in screen 
Csharp :: how to decrease velocity of a Unity rigidbody 
Csharp :: c# tab select tab 
Csharp :: c# fileupload example 
Csharp :: c# check if object is of any generic type 
Csharp :: audio unity 
Csharp :: list of function in c# 
Csharp :: c# array.reduce 
Csharp :: deactivate a gameobject unity 
Csharp :: loading player preferences unity 
Csharp :: C# The request was aborted: Could not create SSL/TLS secure 
Csharp :: c sharp teleporting 
Csharp :: update browserslist 
Csharp :: c sharp convert string time into 24 hours time 
Csharp :: C# scrape html document 
Csharp :: store data between razor pages 
Csharp :: telerik winforms get value of selected rows from grid 
Csharp :: how to check if a file is running in c# 
Csharp :: c# check port in remote pc 
Csharp :: C# http post request with file 
Csharp :: load a form from button c# 
Csharp :: c# networkstream read all bytes 
Csharp :: vb.net windows version check 
Csharp :: static constructor in c# 
Csharp :: self referencing loop detected for property entity framework 
Csharp :: c# sort array 
Csharp :: c# convert xml to list string 
Csharp :: HttpClient .net Core add Certificate 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =