I dont know if anyone is still on this thread but i am having the same problem. everything works perfectly till i add a rigid body to the hit obj.
plz excuse the slightly unorganized Code i have not gotten to cleaning it up.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ProjectileScript : MonoBehaviour
{
Rigidbody rb;
public bool isBullet;
public bool isRocket;
public bool isBomb;
public bool Fired;
public int RoundType;
public float Damage;
public float HEDamage;
public float Velo;
public float FuseTime;
public float MaxLifeTime;
public float LifeTime;
public float Fule;
public float TransTemp;
public float Penitration;
public float SpredDistance;
public int Cluster;
public float ExplosiveRange;
public float FrieRange;
public float FrieStrength;
public float FrieTime;
public float SlowRange;
public float SlowedVelo;
public bool Slowed;
public float Bulletlength;
public bool Loaded;
public bool Firing;
public bool Armed;
public LayerMask LayersHit;
public float BarelTime;
public float Rounds;
public bool TestBool;
public float TestValue;
public GameObject MagRound;
public bool IsLoading;
public bool BaseRound;
public Transform ProjectileTransform;
public Transform ProjectileTransformR;
// Start is called before the first frame update
void Start()
{
rb = GetComponent();
rb.isKinematic = true;
}
// Update is called once per frame
void Update()
{
if (IsLoading==true)
{
rb.AddForce(transform.forward * 0.1f, ForceMode.Impulse);
IsLoading = false;
}
if (LifeTime <= MaxLifeTime- BarelTime && Armed==false)
{
Armed = true;
}
if (Fired == false)
{
if (ProjectileTransform != null&&Loaded==true)
{
transform.position = ProjectileTransform.position;
transform.rotation = ProjectileTransformR.rotation;
}
}
if (Fired==true)
{
//BULLET STUFF////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isBullet)
{
CheckHit();
LifeTime -= Time.deltaTime;
if (LifeTime <= 0)
{
Death();
}
}
//BOMB STUFF////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isBomb)
{
}
//Rocket STUFF////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isRocket)
{
}
}
}
void Modify (float Damage,float HEDamage,float Velo,float FuseTime,float LifeTime,float Fule,float TransTemp,float Penitration,float SpredDistance,int Cluster,float ExplosiveRange,float FrieRange,float FrieStrength,float FrieTime)
{
if (Armed==true)
{
}
}
void CheckHit ()
{
RaycastHit hit;
if (Armed == true)
{
if (Physics.Raycast(transform.position, Vector3.forward, out hit, SlowRange, LayersHit))
{
if (Slowed == false)
{
rb.AddForce(transform.forward * SlowedVelo * -1, ForceMode.Impulse);
Slowed = true;
}
}
if (Physics.Raycast(transform.position, transform.forward, out hit, (.15f + Bulletlength), LayersHit))
{
float Angle = Vector3.Angle(transform.forward, hit.normal);
TestValue = Angle;
Vector3 bounceDirection = Vector3.Reflect(transform.forward, hit.normal);
BasicParrtScript basicParrtScript = hit.transform.GetComponent();
if (basicParrtScript != null)
{
if (basicParrtScript.Armor > Penitration / (180 / Angle))
{
TestBool = true;
basicParrtScript.TakeDamage(0, 0, TransTemp, 0, 0, Angle);
rb.AddForce(bounceDirection * Velo, ForceMode.Impulse);
}
}
if (basicParrtScript != null)
{
if (basicParrtScript.Armor < Penitration / (90 / Angle))
{
basicParrtScript.TakeDamage(Damage, Penitration, TransTemp, HEDamage, ExplosiveRange, Angle);
Death();
}
if (basicParrtScript.Armor / 2 < Penitration / (90 / Angle) && basicParrtScript.TempC >= basicParrtScript.WeakTemp)
{
basicParrtScript.TakeDamage(Damage, Penitration, TransTemp, HEDamage, ExplosiveRange, Angle);
Death();
}
}
}
}
}
void Death()
{
if (Cluster>0)
{
}
Destroy(gameObject);
}
public void Fire ()
{
rb.isKinematic = false;
Fired = true;
LifeTime = MaxLifeTime;
rb.AddForce(transform.forward * Velo, ForceMode.Impulse);
}
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, Bulletlength);
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position, (.15f + Bulletlength));
}
public void Destroy ()
{
Destroy(gameObject);
}
}
9204027–1283955–ProjectileScript.cs (6.18 KB)