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 N1ghtm4r3 · Feb 19, 2013 at 05:47 PM · ontriggeroncollision

OnTrigger & OnCollision not working?

Alright, so I'm building a paper airplane simulator for school, and though I'm very new to javascript, I think I'm doing alright for a beginner. My problem is, I have a script called "blowWind", which is as follows:

 var power : float = 1000.0;
 
 function OnTriggerEnter ( trigger : Collider ) {
     if (trigger.gameObject.name == "paper plane") {
         Debug.Log("Hit the trigger");
         rigidbody.AddForce(Vector3(power,0,0));
     }
 }

I have this script applied to some transparent cubes I created for triggers that have a box collider, and IsTrigger is checked. When I launch my plane, it flies, but when I hit a trigger, it doesn't have power added to it. It doesn't even show up in the console with my debug statement, "Hit the trigger".

My Planeprefab is a rigidbody, with a mesh collider on it, and convex is ticked. I have tried every friggen possibility, and I have every tutorial video from Unity 3D Videos and have watched them all, he has an example video of this very procedure, only he has it print to the console and that is all.

I am very frustrated and stuck at this point, what am I doing wrong? I'd be willing to upload my .unity package if anybody is interested in checking it out, though it isn't quite finished.

Any and all help is greatly appreciated!!

EDIT

Maybe it has something to do with the Planeprefab being a (clone)? I instantiate the prefab, so maybe that has something to do with it?

I feel like it has to do with this plane prefab. I have now attached a script to the ground so that when the paper plane hits it, it loads my main menu for the game, but it isn't detecting the collision, both now have a box collider.

Both scenes are in the project build settings.

Here is the gameover.js:

 function OnCollisionEnter ( myCollision : Collision ){
     if(myCollision.gameObject.name == "paper plane"){
         Application.LoadLevel("Menu");
     }
 }

Thanks for any help everybody, this is killing me.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by N1ghtm4r3 · Feb 19, 2013 at 07:37 PM

Nobody?

It seems like it should be fairly straight forward, not sure what the problem could be.

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 RetepTrun · Feb 20, 2013 at 02:41 AM 0
Share

I reccomend dont try to use an answer to bump the post, cause then your question wont be "unanswered"

avatar image
0

Answer by RetepTrun · Feb 19, 2013 at 06:57 PM

I believe OntriggerEnter acts once only upon entry perhaps this is what you want if you want to give the plane one impulse.

Perhaps you script is on a parent object and the child has the collider?

Anyway I also wanted to make a script that added force to an object in a trigger. http://answers.unity3d.com/questions/140782/artificial-gravity.html Create a big cube, take off the renderer, drop rigidbodies into it, adjust rotation for where to push things

 var forcetype:boolean;
 var gravitytype:boolean;
  
 function OnTriggerStay(other : Collider) {
  
  if(forcetype){
        if (other.attachedRigidbody) {
  
  
  
          // Calculate the y-axis relative to us   
          var cameraRelativeRight : Vector3 = transform.TransformDirection (Vector3.up);
          // Apply a force relative to the our y-axis
  
        other.attachedRigidbody.AddForce(cameraRelativeRight * -9.81,ForceMode.Acceleration);
        }
     }
  
  
 } 
Comment
Add comment · Show 3 · 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 N1ghtm4r3 · Feb 19, 2013 at 09:35 PM 0
Share

Correct, I want it to give it a little thrust, similar to a gust of wind. I'm not exactly sure how the script you posted would help wit what I'm trying to achieve. $$anonymous$$y blowWind script is attached to cubes, with the renderer removed, and it isn't a child object.

I just can't get this to work, and I'm not getting anywhere. I'm ready to pull my hair out.

Thanks for responding anyways, I greatly appreciate it.

avatar image RetepTrun · Feb 20, 2013 at 02:50 AM 0
Share

I noticed something.

You mentioned that your plane is a clone.

You are checking gameObject.name == "paper plane"

In when you make a clone, his name is not "paper plane" it is "paper plane(clone)"

Doublecheck in inspector with game running.

(I reccomend checking using tags ins$$anonymous$$d of names in the long run)

avatar image N1ghtm4r3 · Feb 20, 2013 at 02:52 PM 0
Share

Hey RetepTrun, thank you so much, I'm not sure why I didn't try that, I'm new to unity and javascript, but I got it working using the tag, as you suggested.

You have no idea how thankful I am!! Take care!

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

10 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

Related Questions

OnTrigger, OnCollison 1 Answer

Performance difference between OnCollision and OnTrigger messages? 2 Answers

i can see my objects collide but OnCollisionEnter never called c# 1 Answer

how to access a script, and affect only one of the gameobjects its attached to? 1 Answer

OnTriggerEnter and Exit Not Aligned 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