How to disable rb.isKinematic in one script and apply force in other for the same object at the same time?
Hello, everyone, i've got a problem. I've got a script for physical objects that calculates health, and disables IsKinematic, if health is below certain point.
void Update()
{
if (Health < h2 / 2)
{
GetComponent<Rigidbody>().isKinematic = false;
}
if (Health <= 0)
{
Destroy(this.gameObject);
}
}
}
I'm also using physical raycast in another script, that lowers the physical object's health and applies force to it.
else if (Physics.Raycast(transform.position, cam.transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, phys))
{
Rigidbody rb = hit.collider.gameObject.GetComponent<Rigidbody>();
hit.transform.gameObject.GetComponent<PhysicObj>().Health -= 25;
GameObject sp1 = Instantiate(S);
sp1.transform.position = hit.point;
Destroy(sp1, 3);
rb.AddForce(player.transform.forward * 500);
}
But there's a problem: Force is NOT applying right after isKinematic has been turned off. Only on the second time. How can i fix that? Thanks in advance.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613022417im_/https://answers.unity.com/themes/thub/images/avi.jpg)