• 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 abejfehr · Jul 12, 2019 at 12:16 PM · tilemapcollisions

Invert collision detection for boats

I'm pretty new to Unity so forgive me if this is obvious somehow.

I have a tilemap with a TilemapCollider2D, and the map is a grass island in the middle of water. The water tiles are collidable because I don't want the player to walk in water (this makes sense)

What I'd like to implement now is a boat that the player can enter. The boat should be able to move on water but not go onto land, so basically the reverse of walking.

Is there a way I can "reverse" the collisions when the user switches to/from the boat?

Comment
Add comment · Show 3
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 myzzie · Jul 12, 2019 at 12:57 PM 0
Share

Ignore Collision might work.

avatar image abejfehr myzzie · Jul 12, 2019 at 05:16 PM 0
Share

The reason I don't want to use ignoreCollision is because I have a few tiles that are half water and half land, but I'm starting to think I won't be able to do that.

I was hoping to have these half-water-half-land tiles to have the same collision boundary, just the interaction reversed

avatar image I_Am_Err00r abejfehr · Jul 12, 2019 at 08:48 PM 0
Share

You can create another tilemap that has the same coordinates as your original tilemap and set it up so that the second tilempa doesn't have the tilemapcollider on it; then you can paint in land tiles that don't have the colliders on them and they will line up with the tiles you have that do have colliders; this will give you the effect of the boat kind of driving into the land up until a certain point. See my answer below on layermasks and that should allow the boat to only pay attention to certain colliders depending on their layer.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by I_Am_Err00r · Jul 12, 2019 at 08:20 PM

Try a layer mask, basically it only acts as a collision on what you select or don't select, I forgot exactly which it is:

 public LayerMask mask;

I think from there it should show up in the inspector and then add that to your boat script, just make sure your land layer and boat layer are properly defined.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

112 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

Related Questions

CircleCollider2D is not registering collisions with some tiles in a TileMapCollider2D 1 Answer

Making a tilemap editor within the Unity Editor 2 Answers

Top down tile based detection 0 Answers

Why are there lines on the edges of some of the tiles on my 2D tilemap? 1 Answer

Using ASCII as tiles (roguelike) 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges