Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by zero_null · Aug 11, 2016 at 07:09 AM · rigidbody2dcar

How to avoid one particular rigid-body 2d to be effected by the force applied

I am creating a 2d side scroller Zombie Shooting car race game. In this game I need feature through which player can shoot the zombie from the car as well. The problem is that when I apply force to shoot the bullet toward right, the car also gets effected by that force i.e it just moves allot like in reaction of the bullet shot. I just don't need this behavior. I want the car to remain calm and just shoot. Is there any way to exclude one perticular rigidbody i.e the rigidbody attached to the car from getting the force that the bullet rigidbody is getting ?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Timo_Ho · Aug 11, 2016 at 08:52 AM

Maybe you could make the car rigidbody static while the force is getting applyed?

     car.getComponent(smaller)Rigidbody(greater)().isKinematic = true;
     //shoot bullet
     car.getComponent(smaller)Rigidbody(greater)().isKinematic = false;

and if you want to keep the cars velocity (if it is moving) then use this:

     Vector3 v = car.getComponent(smaller)Rigidbody(greater)().velocity;
     car.getComponent(smaller)Rigidbody(greater)().isKinematic = true;
     //shoot bullet
     car.getComponent(smaller)Rigidbody(greater)().isKinematic = false;
     car.getComponent(smaller)Rigidbody(greater)().velocity = v;
 

Sorry for this mess, but I needed to replace the ">" with (smaller) and (greater), because else they'd get hidden

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by arko · Aug 11, 2016 at 08:58 AM

From my understanding, you are instantiating a bullet and then applying force to the bullet game object which also has a rigidbody on it. If that is the case then the problem is when you are applying force to the bullet rigidbody it also affects with the car as is it is close to the car at the time of applying force. To avoid this problem you need to layered out your car and bullet separately. Change the layer of the car from the inspector to "Car" (of course it wont be their, you have to add it manually) and change the layer of the bullet prefab to "Bullet". Then from Edit>Project Settings>Physics 2D mark out the collision between the "Car" and "Bullet" layer. That should solve the problem. As an extra check make sure both your car and bullet have a 2D collider on it.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

52 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2d physics for cars. The game from the top down 1 Answer

Problem with wheelJoint2D car rotations - my car needs to be able to do double jumps and mid-air rotations. 0 Answers

IsTrigger Effecting collision 1 Answer

Moving Rigidbody2D relative to the mouse. 1 Answer

How do I stop a rigidbody from rotating after colliding with another object? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges