• 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 numberkruncher · Mar 13, 2012 at 09:37 PM · collisioncollidertriggercolliders

Temporarily ignore collisions between player and enemies

When my player collides with an enemy I would like to allow the player to walk through the enemy (with flashing animation to indicate damage).

I thought that this would be best achieved by setting the collider of the enemy to a trigger. But... this is no good because OnTriggerEnter doesn't appear to provide the contact points upon collision (which are essential).

What are my choices?

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

2 Replies

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

Answer by rutter · Mar 13, 2012 at 11:51 PM

If you can get away with it, temporarily disabling one collider by setting Collider.enabled to false would be simple.

Otherwise, you might try setting up collision layers and tweaking GameObject.layer on the player and/or enemy. You could temporarily put one character on a layer which doesn't collide with other characters.

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 numberkruncher · Mar 14, 2012 at 12:00 AM 0
Share

I didn't realise that you could switch between layers dynamically! Do you know if there are any performance issues related to switching between layers at runtime? Cheers

avatar image rutter · Mar 14, 2012 at 12:14 AM 0
Share

Not sure! It seems reasonable to assume there might be some physics complications, but they're probably fine if you're not doing this especially often.

avatar image
0

Answer by nasapc123 · Mar 13, 2012 at 11:50 PM

possibly you could use

 Physics.IgnoreCollision(other.collider, collider);

this would ignore collisions, and then possibly check th distance betwen you and the enemy, or wether the object is inside the trigger using

 OnTriggerStay(){
 //apply damage
 }
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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

changing gravity OnTriggerEnter 1 Answer

OnTrigger event when colliders are already touching eachother 1 Answer

Get position of collision with triggers? 1 Answer

kinematic trigger with static collider-no trigger message? 0 Answers

OnTriggerEnter Not Working 3 Answers

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