- Home /
Rigidbody.AddExplosionForce goes upwards and not outwards
Below is the entirety of my only script being used in a test scene I have created:
using UnityEngine;
using System.Collections;
public class ClickToExplode : MonoBehaviour
{
[SerializeField]
float explosionForce = 10000.0f;
[SerializeField]
float explosionRadius = 5.0f;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
if (Physics.Raycast(ray, out hit, 100.0f))
{
Rigidbody rb = hit.transform.GetComponent<Rigidbody>();
if (rb)
{
rb.AddExplosionForce(explosionForce, hit.transform.position, explosionRadius, 0, ForceMode.Impulse);
}
}
}
}
}
The code works as expected as far as it creates an explosion force when I click on a rigidbody in the scene, but it shoots upwards even though the upward modifier is 0
. What I want is an outward force in all directions so the neighbouring blocks are blown away.
See the picture below for what currently happens very shortly after clicking the block where the red circle is. Notice how the blocks to the side and below are unaffected.
I tried making it -1.0f
and that indeed changes it to a downward force, but anything greater than -0.5f
still shoots up! What am I doing wrong?
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Prevent Rigidbody from Climbing Steep Slopes using Forces (C#) 0 Answers
how to keep a "ship" over a platform or rigidbody? 0 Answers
how get bow to add more force over time 0 Answers