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 deadfish90 · Nov 21, 2012 at 08:16 AM · collidersrigidbodies

Create an environmental hazard area

Hey everybody. I need a bit of guidance. Basically I need to create an area that if a player stands in, he loses health. I've made a few attempts, but have come up short. I tried using a box collider on an empty gameobject, but it sets up the invisible wall. If I make it a trigger, the gameObj is destroyed. Is there an easier way to do it than just set up a bounding area in a script? Does unity have a way to get this effect?

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 asafsitner · Nov 21, 2012 at 08:24 AM 0
Share

Trigger should work fine. You have to check your code and see why the object gets destroyed immediately - are you dealing damage each frame the object is inside the trigger? If so, make sure it's independent of frame rate with Time.deltaTime

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · Nov 21, 2012 at 08:24 AM

this is because your instantly draining his health REALLY REALLY fast. your draining every update and update is called maybe 50 maybe hundreds of times a second.

what you need to do is drain health, delay, drain again.

you need something like a drain health function and then use

invokerepeating(drain_health,delay);

REALLY THOUGH what you need is to read this. http://unitygems.com/mistakes1/ expand the make something happen in the future text by clicking on it.

you'll see this like a few paragraphs in.

The example above shows how to create a timer suitable for triggering an action when the player remains inside a zone. For instance if the player enters a fire zone, simply harming the player in the Update would kill him within a second. With the timer we can harm him every x seconds.

or EXACTLY WHAT YOUR DOING. :)

you'll also see it followed up with.

Still, Unity offers better solutions as shown in the next part.

so you'll probably want to read up on that next part. :P

It will explain in detail exactly how to solve your issue.

Mark as answered and have a nice day. :)

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 Kryptos · Nov 21, 2012 at 09:42 AM 0
Share

Ins$$anonymous$$d of InvokeRepeating, you can use Time.deltaTime to control the speed of health decay.

 void OnTriggerStay(Collider other)
 {
     PlayerScript player = other.GetComponent<PlayerScript>();
     if (player)
     {
         player.health -= healthDecaySpeed * Time.deltaTime;
     }
 }
avatar image deadfish90 · Nov 21, 2012 at 05:30 PM 0
Share

Actually, the player object isn't being destroyed, its the emptyGame obj with a box collider. The only thing the hazard object has is a box collider, with no mesh. The script only sends out a debug when the OnTriggerEnter() is called. Essentially, as soon as my character triggers the box collider, it kills the empty Gameobject.

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

Simplistic Colliders for enemies 1 Answer

Avoid Rigidbody Intersection 1 Answer

Inconsistent Collision Detection 3 Answers

physics.OverlapSphere colliders 1 Answer

How do I make a rigidbody bounce off a mesh collider? 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