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 /
This question was closed Aug 09, 2012 at 12:56 AM by sketchers1 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by sketchers1 · Aug 08, 2012 at 02:53 PM · collidertrigger

Activate Script not Working

I have this script attached to a spaceship:

 var Whatever : GameObject;

function OnTriggerEnter (other : Collider) {

var scriptname : SeekSteer = Whatever.GetComponent("SeekSteer");

scriptname.active = true;

}

The space ship has a a box collider. The box collider has a Trigger. When I shoot the Collider with a bullet (that doesnt have a Trigger). Nothing happens. What am I doing wrong? I also tried attaching the script to another object, and it still doesnt work.

NOTE: The top 3 pictures show a few things about my object: http://unityimageprobs.wordpress.com/

Comment
Add comment · Show 2
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 whydoidoit · Aug 08, 2012 at 04:46 PM 0
Share

Do you have a rigidbody attached to one of the objects?

avatar image sketchers1 · Aug 08, 2012 at 05:51 PM 0
Share

Yes, the Bullet has a Rigigbody

6 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by fafase · Aug 08, 2012 at 05:59 PM

Try removing the "" in GetComponent:

 var scriptname : SeekSteer = Whatever.GetComponent(SeekSteer);

You should by the way cache this command.

 var scriptname :SeekSteer

 function Start(){
   scriptname = GameObject.Find("Whatever").GetComponent(SeekSteer);
 }
 
 function OnTriggerEnter (other : Collider) {
   scriptname.active = true;
 }

I wonder though if you can find a component that is not active.

Comment
Add comment · Show 12 · 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 sketchers1 · Aug 08, 2012 at 06:12 PM 0
Share

That doesn't seem to be working either.... The Box Collider should be a trigger and my bullet shouldn't right? I attached the script to the Box Collider..

avatar image fafase · Aug 08, 2012 at 06:19 PM 0
Share

I would put that script on the trigger object. Are you sur ethe collision is detected already? Add this in the OnTriggerEnter

 Debug.Log("You collide me real hard");
avatar image sketchers1 · Aug 08, 2012 at 06:26 PM 0
Share

I added it, is something supposed to show up?

avatar image sketchers1 · Aug 08, 2012 at 06:27 PM 0
Share

I noticed something really weird: So when I shoot the box collider at first, the bullets explode like they are supposed to, but after awhile they just start going straight through the collider... Is this supposed to mean something??

avatar image fafase · Aug 08, 2012 at 07:05 PM 0
Share

If the collision is detected, you should see You collide e real hard showing up in the console at the bottom of Unity.

OnTriggerEnter is supposed to detect collision but does not resolve it. It means it is like entering a zone without walls. So your bullet should go through. It is not easy to know without the rest of the scripts.

Show more comments
avatar image
1

Answer by 3D Junkie · Aug 08, 2012 at 11:16 PM

the script is a component, not an object, so maybe use .enabled instead of .active?

Comment
Add comment · Show 1 · 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 sketchers1 · Aug 09, 2012 at 12:21 AM 0
Share

That ended up being the problem, but i figured it out, Thanks!

avatar image
0

Answer by TaintedNobodies · Aug 08, 2012 at 04:53 PM

Make sure your bullet that is being shot has a collider and a rigid body.

straight from the Unity Reference Manual:

For a Trigger to collide with a normal Collider, one of them must have a Rigidbody attached. For a detailed chart of different types of collisions, see the collision action matrix in the Advanced section below.

Comment
Add comment · Show 1 · 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 sketchers1 · Aug 08, 2012 at 05:50 PM 0
Share

$$anonymous$$y bullet has a Collider and is a Rigidbody. The Box Collider inside the ship has the Trigger. That is correct, right?

avatar image
0

Answer by Meldow · Aug 08, 2012 at 04:52 PM

try putting some Debug.Log("DetectedCollision"); so you are SURE that the collision occured. 90% of the times the code isnt doing what you want, its because u are considering things that arent happening.

still, little info to give a propper answear

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 TaintedNobodies · Aug 08, 2012 at 11:16 PM

it probably means the speed of the bullet is too fast. On the bullet object, make sure it has the rigid body connected to it. and under the rigid body options there should be a Collision Detection option where you can select. discrete, continuous, or continuous dynamic, i would select either continuous or continuous dynamic, those two options you would want to use for fast moving objects to detect collision.

at the bottom of the unity window you should see it say debug log with the You collide me real hard.

I would adjust your script to this. Add a get tag to make sure that the object coming in contact with the ship is a bullet. Which means make a bullet tag in unity and make sure that the bullet object has that tag. otherwise anything that comes into contact with it will trigger the script. that might be the thing that is messing with you, is if you have the script deactivated something like the ground or something flying or whatever with a collider might be coming into contact and turns on the script.

var Whatever : GameObject;

function OnTriggerEnter (other : Collider) { if (other.gameObject.tag == "bullet") { Debug.Log("You collide me real hard"); var scriptname : SeekSteer = Whatever.GetComponent(SeekSteer); scriptname.active = true; } }

second I would make a dummy script named SeekSteer with just this code

function Update() {

Debug.Log ("SeekSteer scripted turned on");

}

So that this is the script that is turned on. and if it is turned on in the debug log it will keep saying seek steer script turned on over and over and over so that you know you turned it on. Also I know you probably already did it, but make sure the script is unchecked that you want to turn on so it is intact deactivated

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
  • 1
  • 2
  • ›

Follow this Question

Answers Answers and Comments

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

Related Questions

Controller Collider Script 1 Answer

Detect if out of trigger 2 Answers

Action activates trigger. 1 Answer

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

How to get info from child triggers? 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