Question by
Bigbillion · Jun 19, 2018 at 08:14 AM ·
scripting problemrigidbodyraycastaddforceclones
rigidbody,addforce is affecting all clones which are clicked on through raycast
the clones of the object which are coming from the spawner also move when they are again set active in the pooling list! ( i use object pooling to generate objects from a spwner)
void FixedUpdate() {
if (Input.GetMouseButtonDown(0))
{
Rigidbody red = new Rigidbody();
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// Vector3 forward = transform.TransformDirection(Vector3.forward) * 10;
// Debug.DrawLine(transform.position, forward * 100, Color.red);
if (Physics.Raycast(ray, out hit, 100))
{
if (hit.collider.tag == "white tile" || hit.collider.tag == "black tile" || hit.collider.tag == "red tile" || hit.collider.tag == "yellow tile")
{
Rigidbody rb = hit.collider.GetComponent<Rigidbody>();
Vector3 left = new Vector3(-1, 0, 0) * 50f;
rb.AddForce(left);
}
}
}
}
Comment