Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Mar 02, 2020 at 09:26 PM by Zentiu for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Zentiu · Oct 04, 2014 at 10:57 AM · c#collidertriggercharactercontroller

c# trigger collider makes character controller misbehave.

Hiya,

This is a bit difficult to explain so im sorry if its a bit long.

Im making an RTS. So, I have unit that moves with a character controller. I also got a tree in my scene (basically a cube scaled only on its y axis). when I select my unit and make it move anywhere, it works fine.. Also when I click on the tree to make the unit move there it works fine. when the unit nears the tree the unit will do a "gather wood" animation wich works fine. Now I've placed a trigger collider (sphere collider set as trigger) on the tree to detect if there is anyone near it and does the gather wood animation, give wood every second or so.

however, when I click on the tree to make the unit move there instead of moving directly towards the tree, the unit moves between the tree and the inside edge of the sphere collider and spins uncontrollably. the unit always favors a certain spot when the collider is on. when I deactivate or remove the collider and let the unit move towards the tree again it works normally.

I tried different colliders and came to the conclusion that if I either remove or make the collider just to small for the unit to enter, its the same regardless of whether its a box collider, a capsule collider or whatever. if its too big, it will spin uncontrollably inside that collider on the exact same spot as last time which is somewhere between the positive z axis of the tree and the edge of the collider.

Is the collider messing with the character controller collider or something? I know its not a script issue but if it can be fixed through scripting then I prefer c#. Ohw and yes, the collider is set as trigger.

If you need more information, please feel free to ask.

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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by N1warhead · Oct 04, 2014 at 11:38 AM

I've figured out a long time ago when collider don't work, I settle for trying to do a Raycast.

Try doing a raycast. Have the tree or player send out a raycast to the tag of the tree or player, if it's within a certain distance x from the tree or x from the player, then play your animation and do what you need to do with your Gather wood.

So pretty much lets say this is on your player.

if (player) > 5 units from tree > Raycast ticks > Whatever is in your If statement on your Raycast > Activates. If your more than 5 units > The IF statement is voided out unless you go back within > 5 units.

Hope that makes sense?

NOTE - THAT WAS NOT A CODE. AND ALSO LOOK INTO SPHERECAST.

Comment
Add comment · Show 4 · 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 Zentiu · Oct 04, 2014 at 12:52 PM 0
Share

been actually looking a bit into spherecasting (saw it somewhere when I watched the "related questions" on the right side) before you posted your answer but I cant seem to get the spherecast expand like a spherecollider.

I can only make it expand on 1 axis e.g. positive Z axis with transform.forward.

I tried vector3.one but doesn't seem to work and expanding radius doesn't either.

Am I forced to put 8 spherecasts on (like 4 sides + 4 corners of the tree) and play around with Physics.OverlapSphere?

wouldn't that be taxing on performance when I got loads of trees in my scene?

avatar image Zentiu · Oct 04, 2014 at 01:15 PM 0
Share

Never$$anonymous$$d, im an idiot.. had that spherecasting inside a method and the method on void update inside an if statement that always returned false.. :P

Thnx for the help and confir$$anonymous$$g that spherecasting is what I needed.

avatar image Zentiu · Oct 04, 2014 at 01:18 PM 0
Share

By the way, do you happen to know why trigger colliders and character controllers cant work well together? (case I still don't understand why it shouldn't work..)

avatar image N1warhead · Oct 04, 2014 at 01:21 PM 0
Share

Glad you got it working buddy :).

To be honest, I've never had that problem exactly like you have, my stuff either just didn't work or it did lol. If I couldn't get somethign to work I just tried a different path, I hate ray casts, they are complicated. Like I made one the other day and ins$$anonymous$$d of going down. Oh it went down, but when I jumped it would shoot forward, like really? Lol.

But I always end up making my own custom controllers. $$anonymous$$uch easier.

Follow this Question

Answers Answers and Comments

28 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

Related Questions

Destory/Collect object to open door 1 Answer

How do I detect when two CharacterControllers collide? 0 Answers

Trigger help! 0 Answers

OnCollisionEnter not working 1 Answer

Adding force relative to the distance from an 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