0
\$\begingroup\$

I am creating a 2D side-scroller car race game with zombies. In this game, I set up a feature through which the player can shoot the zombies from the car, as well.

The problem is that when I apply force to shoot the bullet towards the right, the car also gets effected by that force, i.e it just moves a lot in reaction to the bullet shot. I don't want this behavior. I want the car to remain calm and just shoot.

Is there any way to exclude one particular rigidbody, i.e the rigidbody attached to the car, from applying the force the bullet rigidbody is using?

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Can you post the code you are using to apply the force ? \$\endgroup\$
    – jgallant
    Aug 11 '16 at 9:10
  • \$\begingroup\$ guys I solved the issue by ignoring collision between the Bullet and Car from PlayerSettings>Physics2D \$\endgroup\$ Aug 11 '16 at 10:01
  • 1
    \$\begingroup\$ Possible duplicate of How to ignore collision between two objects \$\endgroup\$
    – jgallant
    Aug 11 '16 at 10:02
  • 1
    \$\begingroup\$ I dont believe this is a duplicate. While the two questions are solved by the same answer, the original deliberetly asks how to ignore a particular collision. This question asks how to prevent a force from effecting a rigidbody. Similar-ish; but not duplicates. \$\endgroup\$
    – Gnemlock
    Aug 11 '16 at 13:14
  • 1
    \$\begingroup\$ I would also suggest the asker posts their solution as an answer, to help future users. \$\endgroup\$
    – Gnemlock
    Aug 11 '16 at 13:15
1
\$\begingroup\$

the car should be affected. if you apply Newton's laws correctly, the force will be proportional to the mass. hence it appears that you have to increase the mass of the car in your model

\$\endgroup\$
3
  • 1
    \$\begingroup\$ This is not real life, it is a video game. The Car does not have to be affected :) \$\endgroup\$
    – jgallant
    Aug 11 '16 at 9:53
  • \$\begingroup\$ guys I solved the issue by ignoring collision between the Bullet and Car from PlayerSettings>Physics2D \$\endgroup\$ Aug 11 '16 at 10:01
  • 1
    \$\begingroup\$ I think he is saying it should effect the car, in effort to accurately convey physics, just far less significantly than it would. I believe the force would actually be absorbed by the shooters arm, though, so Im not sure how accurate that is. This would still solve the problem; A proportionally heavier car would not have the same magnitude of reaction to the same physics force. It could be messy, depending on how other rigidbodies/physics are set up.. \$\endgroup\$
    – Gnemlock
    Aug 11 '16 at 13:17
0
\$\begingroup\$

As comments suggest that I should answer my own question, since I figured it out. If the bullet is been fired with much force, and its mass is more or less equal to the car, than the car shooting the bullet will be affected.

For the solution, I have ignored the collisions in the editor settings between car and bullet. This may not be the optimal solution, as you might need to have a slight impact on the car when you add force to your bullet rigidbody, in which case you need to decrease mass of your bullet and increase the mass of your car.

Thanks a lot to all who commented.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.