so I was following a game creation series and decided to go of course to add my own things and I added a grenade and here is my following Grenade script which is attached to the player:
using UnityEngine;
using System.Collections;
public class Grenade : MonoBehaviour {
public Rigidbody grenade;
public Transform throwPoint;
public float throwPower;
// Use this for initialization
void Start ()
{
grenade = grenade.GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown(1))
{
Rigidbody clone = new Rigidbody();
clone=Instantiate(grenade, throwPoint.transform.position, throwPoint.transform.rotation)as Rigidbody;
clone.velocity=transform.TransformDirection(Vector3.forward*throwPower);
}
}
}
and heres my explosion script which makes the explosion happened and it is attached to the grenade prefab:
using UnityEngine;
using System.Collections;
public class Explosion : MonoBehaviour {
public float radius;
public float power;
public float explosiveLift;
public float explosiveDelay;
public Transform explosionPrefab;
public Collider[] colliders;
IEnumerator Start ()
{
yield return new WaitForSeconds(explosiveDelay);
Vector3 grenadeOrigin = transform.position;
colliders = Physics.OverlapSphere(grenadeOrigin, radius);
foreach (Collider hit in colliders)
{
if (hit.GetComponent<Rigidbody>())
{
hit.GetComponent<Rigidbody>().AddExplosionForce(power, grenadeOrigin, radius, explosiveLift,ForceMode.Impulse);
Destroy(this.gameObject);
}
}
}
}
so after I throw my grenade and let it explode and effect my enemies what happens is that my enemies propel back which is expected but what isn’t expected is that when they propel back they become glitch and start vibrating and moving very slowly and another thing is that when they attack me they fall right through map.
if u require more information ill be happy to provide it