• 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 Andre_51X · Feb 09, 2019 at 04:47 PM · 2dcollisioncollision detectioncollider2d2d-physics

Make 2D projectile collide only from the outside

Hello everyone, I have a simple yet mind-scratching issue. In my game, I have a 2D object that collides only with projectiles (as intended), but the issue is that when the player is "inside" the collider, the projectile collides as soon as it spawns, not allowing the player to shoot enemies that are in the distance.

I tried using platform effectors with no luck. To make sure I was configuring the effector correctly (to interact only with the projectile layer), I ended up watching a beginner video on how effectors work and it appears that I have been configuring them correctly.

Thanks in advance to whoever might have an idea for a simple but effective solution to this issue!

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 RobAnthem · Feb 09, 2019 at 05:11 PM 0
Share

You could always just do Physics.IgnoreCollision(myPlayer.GetComponent<Collider>(), myProjectile.GetComponent<Collider>()); when you instantiate the projectile.

avatar image Andre_51X RobAnthem · Feb 09, 2019 at 05:15 PM 0
Share

nevermind, I found a really easy solution. The collision issue is not between the projectile and the player, but the projectile and another object that acts as a active background component that the player can shoot. I'll post the solution as an answer, so I can hopefully help anyone that googles a similar issue in the future. Thanks for replying!

avatar image RobAnthem Andre_51X · Feb 09, 2019 at 05:17 PM 0
Share

Don't forget in Edit > Project Settings > Physics you can determine what objects layers can interact with what layers.

1 Reply

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

Answer by Andre_51X · Feb 09, 2019 at 05:18 PM

Ok, apparently I found a solution by myself. The solution is to switch the object's collider to a trigger when the player is inside the collision, like this the projectile won't collide, to then set the trigger to false when the player is outside the area. 2 colliders are involved: a child trigger collider that is set to a layer that collides with the player (so the parent knows when the player is over the interested object) and the parent's collider that is set to the layer that only projectiles can collide with, which will be the collider that alternates its trigger status.

Comment
Add comment · Show 3 · 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 RobAnthem · Feb 09, 2019 at 05:20 PM 0
Share

This seems like a janky solution to a simple problem....

avatar image Andre_51X RobAnthem · Feb 09, 2019 at 05:31 PM 0
Share

The issue is not that I don't want the projectiles to interact with the background object. I do want them to collide with the background object, but I don't want the projectiles to interact with this object when the player is standing in front of it. By default in Unity, when a collider instantiates inside another collider, a collision event happens. This is what I don't want to happen.

avatar image RobAnthem Andre_51X · Feb 09, 2019 at 05:35 PM 0
Share

That makes sense, there would be a few ways to do it, but knowing what your intention is, I can't see anything wrong with your method, unless other objects still need to collide with the now-trigger object. In which case there are some alternatives that don't involve setting the object as a trigger.

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

238 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

How to make a little wiggle room for the collision? 1 Answer

Bullet Trail not destroying on collision 0 Answers

Problem with method Collider2D.isTouchingLayers() 4 Answers

Unity2D - OnTriggerEnter2D not working 1 Answer

Gameobject not detecting collison from other Box Collider 2D [SOLVED?] 1 Answer

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