Question by
Laser_Sight8 · Oct 16, 2017 at 03:01 AM ·
c#rigidbodyrigidbody.addforce
Problem with ExplosionForce radius
I have this code where the player clicks to shoot out an explosion. However it only works when an object is hit directly. If the explosion hits right next to an object the object does not seem to be affected. What am I doing wrong? Thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour {
public GameObject explosion; // The explosion prefab
Rigidbody rb;
public int ExForce = 50;
public int ExRadius = 50;
void Update()
{
if (Input.GetButtonDown("Fire1"))
Shoot();
}
void Shoot()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100))
{
Instantiate(explosion, hit.point, Quaternion.LookRotation(hit.normal));
hit.rigidbody.AddExplosionForce(ExForce, hit.point, ExRadius);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
C# keep previous velocity while jumping, previous solutions not working 0 Answers
Player jumping automatically 0 Answers
How do you fix a Rigidbody stopping quickly after the addforce stops being called? 1 Answer
How to change Force direction immediately? 1 Answer
Rigid body robot animation 0 Answers