- Home /
add force to object that has 2 different rigid bodies
Hi, I have a question and it is important for me to know what could be the approaches to it, because this is always a problem for me. I am trying to make a clone of "push'em all" mobile game. I have a player object that has a rigidbody and it has several game objects on it. And one game object "movingpusher" has also its own rigidbody. Now, if my enemies get in trigger with player object, they push the player forward but, I just use "AddForce" to player object's rigidbody and the result is like at the attached photo.
And this is the code part
private void Awake()
{
EnemyController.PushPlayer += GetDamage;
PlayerRigid = gameObject.GetComponent<Rigidbody>();
}
private void GetDamage()
{
Debug.Log("TakingDamage");
gettingDamage = true;
PlayerRigid.AddForce(StablePusher.forward * 50);
PlayerRigid.velocity = transform.TransformDirection(0, 0, 5);
}
Now, I know I can also use AddForce for the MovingPusher's rigidbody, but I am totally sure this is not a good way, and I will be appreciated if you could share your ideas :)
Your answer
Follow this Question
Related Questions
Rigidbody.velocity seems to be breaking jumping physics 0 Answers
Get result (force & torque) of AddForceAtPosition? 2 Answers
Why is force only being added in the same direction? 1 Answer
How to make rigidbodies on each side of a cube fall towards the cube? [multiple gravity / addForce] 0 Answers
Physics in 2D mode not working? 0 Answers