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 Noah-1 · Jun 25, 2012 at 01:48 AM · arraytriggerdetection

Detecting contact on colliders?

Hi guys, I have a question, currently I am creating some sort of a bridge made of rocks, the bridge is supposed to be a trap, every time you stand on one of the rocks it will start going down into the boiling lava, if you get out of them they are supposed to return to it´s original position, I am trying to use an array to store every rock of the bridge but Im facing problems detecting the rocks in contact with the player, here i what I´ve got so far (pretty weird):

 var rockSelected : GameObject; 
 var trigger : Collider; //Rock Collider
 var rocks : GameObject[]; 
 var triggerTouched : Collider[];
 
 function Start(){
     rockSelected = rocks[0];
     trigger = triggerTouched[0];
     
     if (rocks.length == 0) return; 
     if(triggerTouched.length == 0) return;
 }
 
 //ON-TRIGGER-STAY //***************
 
 function OnTriggerStay(trigger:Collider){
     if(trigger.CompareTag ("TrickyRock")){
         Debug.Log("trap touched!!");
         rockSelected.transform.Translate (0, -1 * Time.deltaTime, 0); //take down the rock slowly
     }
 }

Thanks for your time

Comment
Add comment · Show 4
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 hijinxbassist · Jun 25, 2012 at 08:12 AM 0
Share

you take down the rockSelected, but that rockSelected variable is constant? seems like you would send each touched rock to a Fall function of sorts. Currently, from what i understand, you want the triggered rock to fall s$$anonymous$$dily and not the "constant" rockSelected GO(of which i have no idea what it is). You could just add a line to the current setup, if im not mistaken up to this point, as such

 rockSelected=trigger.transform;
 rockSelected.Translate(....yada);
avatar image jorjdboss · Jun 25, 2012 at 09:21 AM 0
Share

$$anonymous$$y first question is: how do you want the rocks to be returned to its original position? Does it reset to its original position, or does it rewind backwards to its original position(like in Prince of Persia!). Also are you using character controller or rigidbody on the player? Here's how I think is a better way of doing it: Sandwich the rocks inside a box of very thin static colliders, so it appears the rocks are in place. Now as soon as you step on it, you can attach a rigidbody to all six sides of the box and they all start falling. $$anonymous$$ake sure to store the positions and rotations of all the rocks and box faces into an array in when you have to reset the whole bridge.

I'm sorry I didn't put any code because I'm not sure if this is what you want. So do answer my questions above and I'll try and put up some code.

avatar image menep · Jun 25, 2012 at 09:47 AM 0
Share

First You should read the topic http://unity3d.com/support/documentation/Components/class-$$anonymous$$eshCollider.html the most interesting part is at the bottom. Check the table.

Rocks and player need to have a collider. If You want to use triggers You need to check isTrigger = true; In my opinion You should use Rigidbody, non static , because You want to move the player and tricky rocks.

I wouldnt use an array. I would create a prefab of the bridge. $$anonymous$$ain static bridge is parent. Then make the tricky rocks children with all onCollisionEnter scripts and animation, or better make when player enters tricky rock set gravity to true of the rock. It will fall down. If You want the bridge to reset, You can move the tricky rock after for example 10 seconds after hiting the tag = "ground" ; set the position and rotation as it was previously.

avatar image jorjdboss · Jun 25, 2012 at 12:06 PM 0
Share

If you parent it, do you move the parent along with the rocks? if you do that, all the rocks get affected too. If you keep the parent static and make the rocks fall, you can't reset it efficiently as you have to destroy the whole parent hierarchy an Instantiate it again. A simple built-in array can do wonders and are very very fast.

0 Replies

· Add your reply
  • Sort: 

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

Preventing circles in dungeon generation? 0 Answers

Detection if a GameObject is below you or next to you? 1 Answer

Remove object from List after gameObject was destroyed in between Scene loads 1 Answer

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

OnTriggerEnter2D not Working 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