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 /
avatar image
0
Question by Bovine · Nov 10, 2010 at 12:06 PM · collisioncollidercharactercontrollertilelayer

Can a CharacterController ignore one or more Colliders?

Hi All

I am wanting to add a collider to the scene and move it about with my CharacterController for a tile-based game. There are other possible solutions to this, but ideally, when the player moves to another tile, I would move another collider to that tile, effectively reserving the tile and preventing enemies from trying to enter the tile at the same time. I can't see a way that this would be possible, but I was wondering it it could be done with layers? Can a CharacterController be told to ignore a layer? In which case, I can put all these reservations on this other layer and reference that layer when making decisions about where players and enemies can go and this makes it quite easy and efficient (I hope!).

Thanks in advance Ian H

Comment
Add comment · Show 1
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 Bovine · Nov 17, 2010 at 02:40 PM 0
Share

Actually looks like Physics.IgnoreLayerCollision() may do exactly what I am after here.

2 Replies

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

Answer by Bovine · Dec 02, 2010 at 04:55 PM

I solved this by creating a prefab consisting of an empty gameobject with a BoxCollider attached. The box collider takes up a tile and the script controlling movement instantiates two of these prefabs. One always occupies the current 'tile' and the other is inactive until the character moves, at which point the 2nd prefab is activated and placed at the designation tile location. When the controller completes the movement from tile to tile, the first prefab is moved to the controller's new location and the 2nd is set inactive. It us necessary to prevent collision between the CharacterController and these two colliders, and because I use raycasting to determine whether a controller can move into the next square, I have to make the first collider inactive while raycasting.

Sorry if this is a bit hard to grasp from my answer - think of the Box

It seems to be fine and I think I will be able to adapt it to creatures of different size eventually.

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 Proclyon · Nov 10, 2010 at 03:01 PM

May I suggest you solve this program using a programmatical approach with a Grid that can reserve/flag positions as taken/not taken rather than physically blocking off a location? I believe that could help you get a lot more control over what is going on since every tile can be used as an object that way. It has a specific property or behaviour or anything you want keeping all the knowledge clear and open for yourself and any other programmer that will need to dig through the design.

If you really just want to go about it , I would suggest trying to create a temporary clone of your object and remove it's properties that make it visible or controllable in any other way than collisions. Anything that wishes to move simply has to do a range limited (Already a constructor for that exists) sphere or ray cast.

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 Bovine · Nov 17, 2010 at 02:34 PM 0
Share

Yes, as I say, I can do this using a different solution, but being able to use colliders has some advantages: I don't have to create an array potentially as large as the environment which could be expensive; I can have characters take up more or less of a tile depending on their size, so a small character might take up a quarter of a tile, meaning 4 such small creatures could reside on the same tile, or conversely a creature may take up 2x2 tiles. While this is still possible with a grid, it's not so ideal...

avatar image Proclyon · Nov 17, 2010 at 02:51 PM 0
Share

Sorry I can't help you much further now I fear, I don't see another way around this problem myself either. Good luck with getting your problem solved :), If you want you can post your own answer or accept another's here so it can aid the rest of the community. That of course is totally up to you

avatar image Peter G · Nov 29, 2010 at 03:33 AM 0
Share

I agree w/ Proclyon. A multi-dim array seems to me to be a better option. If you are only storing ints or Vector3's it wouldn't be all that expensive, or a custom type. I understand where you are co$$anonymous$$g from, and it makes some sense. Have you tested that changing an array is going to be slower that the physics calculations b/c I would be surprised if that is the case?

avatar image Bovine · Dec 02, 2010 at 05:08 PM 0
Share

I'm not saying it can't be done, or that I won't revert to a multi-dim array in the future, but I feel that using colliders provides more flexibility for a lower footprint, but at arguably a greater computational cost.

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

No one has followed this question yet.

Related Questions

Efficient generation of 2d polygon collider 0 Answers

How do you change the collisions of all of one sort of tile on a tilemap. Also, how do you change the collision box on tiles in your tilemap 0 Answers

Making Colliders/Triggers or Rigidbodies move a Character Controller 5 Answers

OnCollisionEnter Push Object Problem 0 Answers

Can static objects detect collisions 2 Answers


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