• 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 Juli15 · Aug 17, 2018 at 08:10 AM · triggercollider2dtriggering animation box collider

Troubles with "isTrigger"

Hi, good morning. I've seen a lot of questions with related topics but at the end, I'm not finding a solution which I know it will be actually stupid... I'm setting up a 2D scene which has:

  • A background with a collider2D at the bottom (the floor).

  • One zombie acting as a player, you can move him left and right.

  • An ord of zombies coming from the right which are enemies.

I want to allow the player to walk through the enemies and attack whenever he wants. The thing is that when I'm activating the 'isTrigger', the player is automatically falling from the platform (because he's colliding with it, you can see him falling on the photo). alt text I tried to put Kinematic and yes, the enemies can pass over it and it doesn't fall but it's not the objective because with this case you cannot move the player. What should I do? I feel that I'm wasting too many hours with this...

zombiefalling.png (128.3 kB)
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 goddatr · Aug 17, 2018 at 01:05 PM 0
Share

You can move the player when Is$$anonymous$$inematic is on. (get a look at this method : https://docs.unity3d.com/ScriptReference/Rigidbody.$$anonymous$$ovePosition.html )

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Ermiq · Aug 17, 2018 at 11:13 AM

You could put your enemies in their separate layer and set your player collider to ignore collisions with objects in that layer. Here's a script you could use: https://forum.unity.com/threads/ignorecollision-by-layer.3226/

Comment
Add comment · Show 2 · 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 Captain_Pineapple · Aug 17, 2018 at 12:48 PM 0
Share

but will this not cancel out any trigger interaction between these layers as well?

avatar image Ermiq Captain_Pineapple · Aug 17, 2018 at 04:06 PM 0
Share

Hm... Yes, you're right. Then maybe use 2 colliders on player zombie: first one for rigidbody physyics and set it to ignore enemies layer, and second one set to 'IsTrigger' for the fights. Say $$anonymous$$ovingCollider = GetComponent<CapsuleCollider2D> (); TriggerCollider = GetComponent<BoxCollider2D> ();

avatar image
0

Answer by Captain_Pineapple · Aug 17, 2018 at 10:30 AM

Hey there,

well there is a solution that comes to my mind but it's most certainly not the most pretty one:

Give your enemys as well as your normal character each a trigger collider and a normal collider. Then whenevery ou spawn an enemy you call the function Physics2.ignoreCollision with the normal colliders of your character and the enemy.

This should render all "normal" collisions obsolete and will still enable you to walk on the ground. The ugly point about this is: You really have to make sure to call an ignore collision between all your players colliders and all your enemey colliders each. If you forget one that will result in strange things and probably will be difficult to debug.

Should in theory solve your problem though. Good luck with your game, graphics look neat :)

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

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

Why does my trigger only fire one time? 0 Answers

Make particle system cover a part of the parent, depending on the the part of the object that is colliding 0 Answers

OnTriggerEnter2D acting like OnTriggerStay2D 0 Answers

Have 2 colliders on same trigger (and hit the first to enter) 0 Answers

Unity2D - OnTriggerEnter2D not working 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