Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

2d explosion unity

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 :: unity animation length 
Csharp :: how to remove from list from index c# 
Csharp :: symfony debug bar 
Csharp :: or operator in c# 
Csharp :: unity read console log 
Csharp :: register all services microsoft .net core dependency injection container 
Csharp :: while loop in c# 
Csharp :: how to add a ddos api to a c# console app 
Csharp :: how to use date range picker in asp.net C# 
Csharp :: This page contains six pages, created with MigraDoc and scaled down to fit on one page 
Csharp :: vb.net read registry key as string 
Csharp :: set time on audio source unity 
Csharp :: c# webbrowser upload file 
Csharp :: lock a cache in asp.net 
Csharp :: O thread de chamada não pode aceder a este objecto porque existe outro thread que já o tem 
Csharp :: c# Class instance 
Csharp :: asp.net core 6 get current culture in controller 
Csharp :: turnary operator c# 
Csharp :: c# datagridview select row index programmatically 
Csharp :: C# dest 
Csharp :: conditional middleware .net core 
Csharp :: c# aabb box rotate 
Csharp :: how to get scene color to work with urp unity 
Csharp :: c# remove duplicate cards 
Csharp :: c# convert float to string 
Csharp :: convert a string to an integer without using library 
Csharp :: unittest servicector automapper 
Csharp :: c# Jarray tryparse 
Csharp :: händelsereportage 
Csharp :: set teh screen rect of camera unity 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =