Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by brag42 · Jan 24, 2013 at 02:54 AM · ontriggerenteroncollisionenter

How do I use an enemy's OnTriggerEnter to collide with stationary player?

I have a player ship and many enemy ships (prefab). I want the ship to collide with enemies (ship takes damage, enemies are destroyed), but I don't want enemies to collide with enemies (don't want them to destroy each other).

Here's how I have tried to do this. Ship and enemy prefab have Colliders, ship has a Rigidbody. Ship is the Trigger. I use OnTriggerEnter in the ship's script.

Problem: if the ship is stationary, enemies pass right through it.

How do I get enemies to ignore each other, but collide with the the stationary ship? If I need to use Triggers then I will. If I shouldn't use Triggers, please tell me that also.

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 jmgek · Jan 24, 2013 at 03:46 AM 0
Share

Do you have a box collide on your ship?

avatar image brag42 · Jan 24, 2013 at 03:47 AM 0
Share

@jmgek: Yes, the ship is a cube and has a box collider.

avatar image jmgek · Jan 24, 2013 at 03:51 AM 0
Share

I really have no idea what you are trying to do, I dont know if its 3D or 2D etc, but either way if you want the ships to ignore eachother. Put a raycast infront of them and use a type of path finding, then transform them to 'player ship' and also use a OnCollisionEnter.

http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html

I hope this helps, other then that I am lost on what you are trying to get at.

2 Replies

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

Answer by aldonaletto · Jan 24, 2013 at 04:16 AM

Simply add kinematic rigidbodies to the ship and the enemies: trigger events will be generated no matter if the ship is static or moving.

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 brag42 · Jan 24, 2013 at 06:49 PM 0
Share

@aldonaletto: Thank you for your answer. I made the ship kinematic and now the enemies collide when the ship is stationary. After your suggestion, I read about non-kinematic collisions and found out they "fall asleep" when stationary. That's why the enemies pass through my sitting ship.

avatar image aldonaletto · Jan 24, 2013 at 10:37 PM 0
Share

I suspect that the reason is different: apparently, the collision system only tracks rigidbodies (kinematic or not), thus it can detect when a rigidbody hits a collider, but not the other way around. As a rule of thumb, any moving collider should have a kinematic rigidbody for the collision system to work. Non-kinematic rigidbodies "go to bed" when not moving in order to reduce the CPU load, but they wake up when another rigidbody collides with them.

avatar image brag42 · Jan 25, 2013 at 08:07 PM 0
Share

@aldonaletto: I didn't think it would work to put a Rigidbody on the enemy prefab too, but it did. It's working exactly how I want it to. Now I just need to understand collisions and triggers better. Obrigado, Aldo!

avatar image Maskeowl · May 03, 2021 at 06:36 PM 0
Share

I want the exa$$anonymous$$er in an area to perceive that there are no enemies around, but when he detects the player, he immediately opens the door, even if there is an enemy inside, how can I fix it?

avatar image
0

Answer by cdrandin · Jan 24, 2013 at 03:48 AM

This should help you http://docs.unity3d.com/Documentation/ScriptReference/Physics.IgnoreCollision.html

Comment
Add comment · Show 1 · 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 brag42 · Jan 24, 2013 at 03:52 AM 0
Share

@cdrandin: Thank you, that looks very useful. I need to go try it out.

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

12 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

Related Questions

Character controller collider? 0 Answers

OnTriggerEnter2D only one time 1 Answer

how to make a bullet that'll be like a missile. 2 Answers

OnTriggerEnter with exact spot of collision 2 Answers

onCollisionEnter vs onTriggerEnter 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