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 ANiceSunset · Jul 11, 2012 at 08:48 PM · platformcollide

How to make platform detonate when player collides?

I tried looking through previous questions to avoid repeates but I haven't found one yet... If there was then i apologize and would appreciate it if I was redirected there.

But here is my question. I'm trying to make the platform explode/detonate when the player, it's a First Person Controller,collides with it. In other words, when the player jumps on top of the platform, the platform will detonate.

There will be multiple platforms but i'm trying to get one working as of now. I have made a separate empty object called PlatformExplode and a script "explode" associated with the empty object with this in it

var player : GameObject;

var enemy : GameObject;

function Update () {

if(player.collider == enemy.collider)

{

Instantiate (explosion, transform.position, Quaternion.identity);

}

}

Am I missing something? Nothing is happening.

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 Maddogc · Jul 12, 2012 at 07:23 PM 0
Share

Unitys Explosion Framework should have all the pretty cool explosion stuff you will need. Did you already have a look at it...

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by C-Blunt · Jul 12, 2012 at 08:04 PM

Apologies for the C# but this is a script from a game im working on at the moment. It works without any issues.

if(other.gameObject.tag == "enemy"); //make sure you tag your enemies as "enemy" in unity.

{

SpawnExplosion();

}

void SpawnExplosion(){

Instantiate(explosionPrefab, transform.position, Quaternion.identity);

}

}

Ensure both player and enemy have colliders attached and attach this script to your player.

On a side note; try adding some de-bugging to your scripts to find out where the problem lies, this will let you know if it's the trigger or the instantiate that isn't working.

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 C-Blunt · Jul 12, 2012 at 08:18 PM 0
Share

Be sure to tick the box that says "is trigger" in the unity inspector on your enemy's collider.

avatar image ANiceSunset · Jul 12, 2012 at 08:46 PM 0
Share

$$anonymous$$ay I ask why a void function is needed? void SpawnExplosion? unless it's syntax related with C#. =P I also found out that I should keep the is trigger on. I kept clicking and trying out different things to see what happens.

I assume that the is trigger is pretty much used for colliders? I mean I made a separate cube to understand the Istrigger. I made the collider a tad bit bigger. If the istrigger is checked, it pretty much blocks the first person. $$anonymous$$inda like a bigger wall. But if it's not checked, the character pretty mucuhu walks through it.

Long story short. Thank you for your help.

avatar image
0

Answer by blackmethod · Jul 12, 2012 at 08:11 PM

In javascript I would use something like.

 function OnTriggerEnter(other:Collider)
 {
    if (other.tag == "Player)
     {
     // Code for detonation
 
     }
 }

Before you try it, click on your character in the inspector and on the very top menu, change the tag to "Player" so this works. I don't know how to code the detonation, so if you know how just put it in there.

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 blackmethod · Jul 12, 2012 at 08:12 PM 0
Share

Oops, I forgot the other quotation mark -.-

Should be: if (other.tag == "Player")

Also make sure to make the box a trigger. By ticking "is trigger" box as well. Thanks C-Blunt

avatar image ANiceSunset · Jul 12, 2012 at 08:47 PM 0
Share

Thanks for your help. I got it. :D

avatar image
0

Answer by Ingen · Jul 12, 2012 at 09:33 PM

otherwise you can not check is Trigger, to pass through, and use OnCollisionEnter

here some reference

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

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

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

8 People are following this question.

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

Related Questions

Issue with Collisions due to Parenting script 0 Answers

Making the object collide while moving in the forward dir. (Vector3.forward) 1 Answer

Turn on Script when collide with this object? 1 Answer

My character will fall through the floor with this script:... 1 Answer

Fps Ladder script... 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