- Home /
Question by
JiveViking · Jul 30, 2020 at 09:39 PM ·
rigidbody2drigidbody.addforcerigidbody.velocityrigidbody-collisionrigidbody physics
Do rigid bodies with force add force to other objects?
The solid collider of a projectile adds force to my player's rigid body, also a solid collider, which I dont want to happen. The projectile is untagged and there isnt a script for this to happen in either gameobject. Is this just a mechanic in unity? If so is there a setting to change it?
The projectile is a bomb, which instantiates an explosion as a child, so there is this script that adds force but a bool is checked that becomes true when the explosion is instantiated
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == "Player" && Exploded == true )
{
playerpos = col.gameObject.transform.position;
pushDir = playerpos - transform.position;
pushangle = Mathf.Atan2(pushDir.y, pushDir.x) * Mathf.Rad2Deg;
vectorAngle = Quaternion.AngleAxis(pushangle, Vector3.forward) * Vector2.right;
col.gameObject.GetComponentInParent<Rigidbody2D>().AddForce(vectorAngle * pushForce);
}
}
Comment