unity rb.addexplosionforce 2d
C#
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);
}
}public class Test : MonoBehaviour {
public float explosionStrength = 100;
void OnCollisionEnter2D( Collision2D _other)
{
if (_other.collider.gameObject.name == "Bouncy object")
_other.rigidbody.AddExplosionForce(explosionStrength, this.transform.position,5);
}
}
Also in C#:
- Title
- c# object clone
- Category
- C#
- Title
- get specific object in list c#
- Category
- C#
- Title
- c# resize bitmap
- Category
- C#
- Title
- replace all ponctuation characters c#
- Category
- C#
- Title
- how to see if they are aholding down a key unity
- Category
- C#
- Title
- how to change player cursor c# script unity
- Category
- C#
- Title
- c# list remove item based on property duplicate
- Category
- C#
- Title
- snippet to create constructor in asp.net c#
- Category
- C#
- Title
- c# reverse array
- Category
- C#
- Title
- c# inline if
- Category
- C#
- Title
- add new page to site c# programmatically
- Category
- C#
- Title
- pop up element from specific index in array
- Category
- C#
- Title
- c# split a string and return list
- Category
- C#
- Title
- check if multiple variables are null c#
- Category
- C#
- Title
- c# implement ienumerable t
- Category
- C#
- Title
- unity try get component
- Category
- C#
- Title
- unity3d find y position on navmesh
- Category
- C#
- Title
- c# windows application get current path
- Category
- C#
- Title
- unity find object by name
- Category
- C#
- Title
- Assets\playermove.cs(30,37): error CS1003: Syntax error, ',' expected
- Category
- C#
- Title
- check connection c#
- Category
- C#
- Title
- install .net sdk ubuntu 20
- Category
- C#
- Title
- .net identity seed users and roles
- Category
- C#
- Title
- c# typeof
- Category
- C#
- Title
- linq c# object except two lists
- Category
- C#
- Title
- c# string array
- Category
- C#
- Title
- windows forms iterate through all controls
- Category
- C#
- Title
- list contains type c#
- Category
- C#
- Title
- how to clear console through script unity
- Category
- C#
- Title
- unity next scene
- Category
- C#
- Title
- linq c# or
- Category
- C#
- Title
- convert string to double c#
- Category
- C#
- Title
- initialise icollection c#
- Category
- C#
- Title
- c# skip following code in loop
- Category
- C#
- Title
- c# ref
- Category
- C#
- Title
- unity invoke
- Category
- C#
- Title
- c# shorten an method
- Category
- C#
- Title
- .net core identity get user id
- Category
- C#
- Title
- c# loop
- Category
- C#
- Title
- freeze position unity c#
- Category
- C#
- Title
- c# code snippet template
- Category
- C#
- Title
- how to draw a dot in c#
- Category
- C#
- Title
- order by C#
- Category
- C#
- Title
- how to open new form on button click in c# xamarin
- Category
- C#
- Title
- unity load scene
- Category
- C#
- Title
- while loop c#
- Category
- C#
- Title
- matplotlib measure the width of text
- Category
- C#
- Title
- gfortran: declare an array
- Category
- C#
- Title
- c# make string null
- Category
- C#
- Title
- replace double backslash with single backslash c#
- Category
- C#
- Title
- c# append array
- Category
- C#
- Title
- c# directories loop
- Category
- C#
- Title
- convert generic to type c#
- Category
- C#
- Title
- c# int
- Category
- C#
- Title
- c# console writeline color
- Category
- C#
- Title
- page parent wpf
- Category
- C#
- Title
- membership get user id
- Category
- C#
- Title
- .net core convert keycollection to array
- Category
- C#
- Title
- unity deactivate scripts in list
- Category
- C#
- Title
- how to switch scenes unity
- Category
- C#
- Title
- how to add to a list c#
- Category
- C#
- Title
- onmouseclick unity
- Category
- C#
- Title
- add object to list c#
- Category
- C#
- Title
- c# access session in class
- Category
- C#
- Title
- nullable unique constraint ef
- Category
- C#
- Title
- kill child C#
- Category
- C#
- Title
- c# switch case with or condition
- Category
- C#
- Title
- How do i destroy a prefab without the error?
- Category
- C#
- Title
- unity input get axis
- Category
- C#
- Title
- c# clear console read chache
- Category
- C#
- Title
- or in unity c#
- Category
- C#
- Title
- c# list to string
- Category
- C#
- Title
- unity rotate around point
- Category
- C#
- Title
- how to say or in c#
- Category
- C#
- Title
- c# file exist
- Category
- C#
- Title
- how to run csharp in visual studio code
- Category
- C#
- Title
- unity get velocity of gameobject
- Category
- C#
- Title
- c# postfix increment operator overload
- Category
- C#
- Title
- if statement conditions c#
- Category
- C#
- Title
- c# adding to a list
- Category
- C#
- Title
- vb.net yes no cancel
- Category
- C#
- Title
- enums c#
- Category
- C#
- Title
- check version of asp.net core
- Category
- C#
- Title
- unity rigidbody constraints
- Category
- C#
- Title
- c# string array to string
- Category
- C#
- Title
- unity rotate object relative to camera
- Category
- C#
- Title
- message authorization has been denied for this request. fiddler
- Category
- C#
- Title
- call a function c#
- Category
- C#
- Title
- void start
- Category
- C#
- Title
- sqlite connection c#
- Category
- C#
- Title
- c# get executable path
- Category
- C#
- Title
- serilog loglevel order
- Category
- C#
- Title
- C# resize window without title bar
- Category
- C#
- Title
- unity change text color
- Category
- C#
- Title
- vb.net drag window without titlebar
- Category
- C#
- Title
- How to search for a string from readline in c#
- Category
- C#
- Title
- c# change cursor
- Category
- C#
- Title
- draw sphere cast unity with program
- Category
- C#
- Title
- c# md5 int
- Category
- C#
- Title
- unity set position
- Category
- C#