Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by darryldonohoe · Jul 25, 2012 at 06:46 PM · collidersontriggerentertriggers

When player enters triggerzone call function

Hi,

I seem to have a problem when entering a triggerzone. What i am trying to achieve is, whenever the player enters a certain zone (a well lit zone) What i tried to do is, put a sphere collider on the point light and attach this script:

var playerSanity : playerSanity;

function OnTriggerEnter(other : Collider) {

  if(other.gameObject.CompareTag("Player"))
  {
      Debug.Log("TEST");
      playerSanity.RegenerateFear();
  }

Also use the collider as a trigger.

But this doesn't work. I also tried some tutorials that i could find on google. But they used the same method and didn't work either. Does anyone know a way how to achieve this?

Thanks,

Darryl

Comment
Add comment · Show 6
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 darryldonohoe · Aug 06, 2012 at 07:30 AM 0
Share

Is it possible that if i purchase Playmaker, that this would work? Cause i saw a tutorial which explains basically what i need. But if Playmaker uses the same method, there will probably be a high risk that it will not work. But if it uses another method, than it probably will. Because i still don't know what the problem is. I just cant figure it out.

avatar image Seth-Bergman · Aug 06, 2012 at 07:42 AM 0
Share

Try changing it to

Debug.Log(other.gameObject);

Debug.Log(gameObject);

you must have something else in the scene tagged as player, or something else with this script attached, or $$anonymous$$AYBE your collider is scaled too big, try lowering the size of the collider component on the object

I don't know about Playmaker but this is a solvable issue, some detail is being overlooked is all

am I correct that the issue is still it activates on Start? this can ONLY mean the trigger is in contact with something tagged as Player, maybe the light, or one of its components

see what the above debug tells you

avatar image darryldonohoe · Aug 06, 2012 at 09:05 AM 0
Share

I will take a look maybe you are right, that there are multiple objects tagged as player. Or something else. I'll also check the Debug.Log, what is it tells me. And once i have that checked. I'll post results here.

Thank you!

avatar image Seth-Bergman · Aug 06, 2012 at 09:21 AM 0
Share

no prob, hang in there!

by the way, something else I noticed since my prior advice..

setting the trigger to "is$$anonymous$$inematic" is a BAD idea, leave is$$anonymous$$inematic unchecked, and be sure to turn off gravity, otherwise I've found the trigger won't work unless it $$anonymous$$OVES (collision matrix doesn't mention that part)

but only an issue if the player does NOT have a rigidbody

otherwise, I find the collision matrix to be a very useful guide

avatar image darryldonohoe · Aug 15, 2012 at 09:47 PM 0
Share

Well i got it to work finally! I used the standard method. Same setup, different project. I think it had some problems with a script or an object in my old project. Cause right now it works like a charm. And i can finally wrap this feature up. Thanks for helping my out on this one Seth!

Show more comments

2 Replies

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

Answer by Seth-Bergman · Jul 25, 2012 at 07:06 PM

     var playerSanity : playerSanity;  //type and identifier same? If the data type is 
                                //"playerSanity", the var name needs to be something different
 
     function OnTriggerEnter(other : Collider) {
 
    Debug.Log("entered trigger"); // see if the trigger was entered before checking tag
 
     if(other.CompareTag("Player")) //don't need "gameObject"
     {
         Debug.Log("TEST");
         playerSanity.RegenerateFear();
     }
 
 }

not sure what the problem is though. See if adding a Debug.Log as above gets called, to rule out issues with the tag..

EDIT : sorry, forgot to mention before

You also need to have a rigidbody on one of the objects..

http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html

the matrix at the bottom of this link will explain what types of objects can send trigger message

just add a rigidbody to the trigger object and set "isKinematic" true

EDIT: now I think DO NOT set isKinematic true, this may cause the trigger not to work (unless it moves) as described by my experience here

but that's only if the player does NOT have a rigidbody, I believe

Comment
Add comment · Show 11 · 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 darryldonohoe · Jul 25, 2012 at 08:59 PM 0
Share

I tried your script, but it didn't worked either. I can walk through the trigger collider, but the debug log before tag is checked isn't showing up. I thought something like this, was supposed to be simple.

Thanks anyway, i am going back to google. See if i can find any tutorials or reference scripts.

avatar image darryldonohoe · Jul 25, 2012 at 09:39 PM 0
Share

I just tested the ones on the reference site, they didn't worked either. I also tried to use OnControllerColliderHit on the character controller. But the same problem. I tested the reference ones on the Player itself and on other game objects. It shows no debug log or anything.

avatar image Seth-Bergman · Jul 25, 2012 at 09:43 PM 0
Share

You also need to have a rigidbody on one of the objects..

http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html

the matrix at the bottom of this link will explain what types of objects can send trigger message

just add a rigidbody to the trigger object and set "is$$anonymous$$inematic" true

avatar image darryldonohoe · Jul 25, 2012 at 09:54 PM 0
Share

The only one that is sort of working is the kinematic one. I tried this a few hours ago, but it gave me a message even though i was not in the trigger zone. It also didn't respond when i entered.

avatar image Seth-Bergman · Jul 25, 2012 at 10:11 PM 0
Share

sounds like the collider was just in the wrong position somehow. that's definitely the way to accomplish this

try again, and keep an eye on where the collider is, the only way you entered that function is by hitting a trigger

Show more comments
avatar image
0

Answer by DaveA · Jul 26, 2012 at 09:53 PM

Make sure 'Is Trigger' is checked.

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

7 People are following this question.

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

Related Questions

On Trigger enters being called a frame late 1 Answer

How do I prevent multiple triggers using OnTriggerEnter? 1 Answer

OnTriggerEnter Multiple Collisions Activating. I tried many variations, Please help (Java) 3 Answers

Can't call GetKey inside OnTriggerEnter? 2 Answers

Hello, How would one make a particlesystem activate triggers? (hopefully I worded that right) 0 Answers


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