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
1
Question by GlitchCrew · Sep 05, 2017 at 01:59 AM · physicscollidercharactercontroller

Collider attached to a character controller doesn't work

Hi, I'm working on action game and I have a problem with guns because they can shoot through walls, check this gif:

Alt text

The player has a character controller, the gun is a child to player's hand. The gun has a box collider (not trigger) with a kinematic rigidbody and doesn't use gravity. But as you can see it doesn't collide with anything at all and allows player to kill enemies through walls which is obviously not very good.

I've tried a gun with a collider only but that doesn't work too.

Of course I could've increased character controller radius so that it includes the whole gun but that makes impossible to the player to walk through thin corridors.

So, any ideas why doesn't this setup work and how can I solve this problem?

Comment
Add comment · Show 6
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 nt314p · Sep 05, 2017 at 10:23 PM 0
Share

Why doesn't the gun collide with the wall?

BTW nice game!

avatar image Cornelis-de-Jager · Sep 05, 2017 at 11:12 PM 0
Share

$$anonymous$$aybe try makign the Guns collider non-kenematic?

avatar image GlitchCrew Cornelis-de-Jager · Sep 06, 2017 at 03:54 AM 0
Share

The gun just floats in space if it's rigidbody is non-kinematic.

avatar image Cherno · Sep 06, 2017 at 03:59 AM 1
Share

You'd nbeed a RB-based character with a compound collider that includes a collider for the weapon for this to work the way you want it.

avatar image GlitchCrew Cherno · Sep 06, 2017 at 04:40 AM 0
Share

While this solution indeed makes it impossible to the gun to go throught walls, it also adds more complexety and problems to my project so I'd rather stick to using just a character controller.

avatar image nt314p GlitchCrew · Sep 08, 2017 at 10:32 PM 1
Share

Hmmm, I'm not sure there's any other way to do it other than what @Cherno said (and I'd rather have a solution with a lot of work than no solution at all).

3 Replies

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

Answer by GlitchCrew · Oct 12, 2017 at 03:38 AM

Okay, I've managed to solve that issue. Like @Cherno said, child colliders can only affect rigidbody-based character but switching from character controller to rigidbody was not an option in my case.

So, now my setup looks like this: every gun has a trigger collider. a kinematic rigidbody and a collision checking script. That script simply has a bool variable canShoot, which is set to be true in every FixedUpdate and is set to be false OnCollisionStay (so now we can know whether it collides with anything at any given frame). And then we use that bool to allow or block every single shot, simple!

Check that gif:

AltText

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
0

Answer by connorwforman · Sep 05, 2017 at 10:45 PM

Go onto the character controller, remove the collider and change it into a box collider. From there, edit the collider, to make it fit the character and the gun. That should work.

Comment
Add comment · Show 1 · 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 GlitchCrew · Sep 06, 2017 at 03:48 AM 0
Share

I can't remove collider from the character controller because there is none attached. Anyway, I've tried ADDING box collider to the player and it didn't change anything at all. The collider just doesn't collide with anything.

avatar image
0

Answer by unit_nick · Sep 06, 2017 at 05:12 AM

If isKinematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore. https://docs.unity3d.com/ScriptReference/Rigidbody-isKinematic.html

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

134 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 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 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

Guidelines for using rigidbody, collider, CharacterControllerScript, etc? 3 Answers

How to deal the 2d platform physics? 0 Answers

Can't raycast on Character Controller? 1 Answer

Static collider vs Character controller? 1 Answer

CharacterController.Move becomes really slow after I move seperate colliders 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