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
1
Question by rafrafi · Mar 17, 2012 at 12:12 AM · trigger

how to force a trigger to detect enemy not moving

hi is this a way to force a trigger to detect an object in x time?? something like a predefined function in unity.

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 Owen-Reynolds · Mar 17, 2012 at 01:38 PM 0
Share

Do you mean ins$$anonymous$$d of picking up the ammo can when you get near, you have to stay near for 2 seconds? There's nothing special for that -- just program$$anonymous$$g to manually count-down and make sure you're still near it.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Mar 17, 2012 at 12:25 AM

This question isn't clear. There are trigger events to detect when an object enters the trigger (OnTriggerEnter), exits the trigger (OnTriggerExit) or to be fired while the object is inside the trigger (OnTriggerStay - sent each physics cycle).
If the trigger is static, it will detect moving rigidbodies or CharacterControllers that enter it. If the trigger moves and the object is static, add a kinematic rigidbody to the trigger.

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

Answer by rafrafi · Mar 18, 2012 at 01:05 AM

i want trigger detect a no-moving character controller so i want a function that force detecting in the time i want.

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

Answer by Kleptomaniac · Mar 18, 2012 at 03:42 AM

Hmm, still not very clear but perhaps something like this:

 private var wasStoppedSinceNow : float; //Typecast as a float so you can increase by decimal increments if you want
 private var timeToStop : float = 5;
 private var rate : float = 1;
 
 function OnTriggerStay (hit : Collider) {
     var targetHit : GameObject = hit.collider.gameObject;
     if (targetHit.tag == "enemy" && wasStoppedSinceNow >= timeToStop) {
         if (targetHit.GetComponent("CharacterMotor").movement.velocity == Vector3.zero) {
             //Do whatever you want to do here and then once your function is finished
             wasStoppedSinceNow = 0;
         }
     } else if (wasStoppedSinceNow < timeToStop) {
         wasStoppedSinceNow += Time.deltaTime * rate;
     }
 }

I'm not even sure if this will work, let alone if this is what you want.

EDIT:


Changed the script to account for time ... haven't tested so it won't be perfect ... I'd say your question is probably too generalised and unspecific to generate a perfect response anyway, but whatever.

Hope that helps, Klep

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 Owen-Reynolds · Mar 18, 2012 at 03:15 PM 0
Share

For the part about time, you add an extra wasStoppedSinceNow variable. Enter sets to the current time (or 9999 -- something that says "no".) Likewise the "else" would also do that. Your if part resets to current time (if it was 99999) and "fires" if wasStoppedSinceow was long enough ago.

Checking veloicity == 0 is safe for a standard CarController script. Unity will quickly set speed to exactly 0. For a rigidbody script, I'm not sure that speed would even be 0 (for example, gravity may keep y at -0.001.)

avatar image Kleptomaniac · Mar 19, 2012 at 10:51 AM 0
Share

Thanks Owen, completely forgot he wanted to account for time. I edited my script, however I'd say there are some areas that may need review ... :P

Oh, and in this case he said he was using a CharController so I didn't account for rigidbodies ...

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

6 People are following this question.

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

Related Questions

Can't click gameobject when over another trigger? 1 Answer

Find all objects currently colliding with trigger 1 Answer

Make triggered sound audible anywhere 2 Answers

2D Style Camera, Shifting at Screen Edge 1 Answer

raycast doesnt seem to collide 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