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 BluEye · Sep 12, 2012 at 12:33 PM · collisioncollidertriggerfps

Collision vs Trigger [Solved]

Going back to square one... again.

Scenario : I am trying to create a maze. At the end of the maze I made a cube that has a box collider on it. Mesh renderer is not checked. It is sized to the area I want it.

Goal : I'd like to have my character enter the area for the game to end (Called finalOut in hierarchy). Close out on it's own but before it does the words "Congratulations" appear on the screen.

Problem : I've tried collision detection vs triggers. Created layers named the one Finalout attached it to the gameobject finalOut, one named player (attached to player). The basic FPS controls are being used (CharacterMotor, FPSInputController, ETC.) Still nothing works.

Question : For what I'd like to happen should I be using a trigger or just collision?

EDIT Script : The script named Trigger_Controller

  public var gameControl : Game_Controller //script that is attached to my player
     
     function OnTriggerEnter ( Other : Collider )
     {
     
         if(other.transform.gameObject.layer==9) 
           //layer nine is named finalOut and on my finalOut game object
         
         //finalOut
         gameControl.finishedTheGame (); 
         //defined in other script
    }


Then this script ^^^ is attached to my GameObject (finalOut)

Thoughts : I'm thinking something to do with the script is wrong. The question is what?

If need be I will post the other one.

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

5 Replies

· Add your reply
  • Sort: 
avatar image
-1
Best Answer

Answer by BluEye · Sep 13, 2012 at 02:12 AM

@vagos21

 function OnGUI ( )
 {
 
     GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity,
     new Vector3(Screen.width / 1024f, Screen.height / 768f, 1)); //My screen size
     if ( GameEnds )
     {
         GUI.Label(Rect (350,350,350,350), "CONGRATULATIONS! GAME OVER");//Centered on the screen
     }
 }
 
 private var GameEnds : boolean;
 function OnTriggerEnter (other : Collider) {
     if(other.transform.gameObject.layer==8){ //I had to change to the layer 8 = player
     GameEnds = true;
     yield WaitForSeconds(3);
     Application.Quit (); //nothing happens with this (I think it's b.c. I'm testing in Unity)
     }
 }
 //attached this whole thing to my GameObject and it worked
 //Just need to increase font size and maybe a colour and I'm good


THANKS EVERYONE FOR YOUR HELP. NOW ON TO THE NEXT PART OF MY GAME

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 vagos21 · Sep 12, 2012 at 09:53 PM

Since you want to make the player be able to walk into the invisible box, you'll use it as a trigger.

Then on your box you'd attach a script that includes this (javascript):

 function OnTriggerEnter (other : Collider) {
     if(other.name == "player"){ //this is actually the name of your player GameObject, you can use a tag or layer instead too
       Debug.Log("Congratulations!");//will print it on the console, but you can change it for a screen message 
       yield WaitForSeconds(3); //wait for 3 seconds
       Application.LoadLevel ("Level2"); //load level 2 supposing you just finished level 1
     }
 }
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 PProductions · Sep 12, 2012 at 02:47 PM

I would use OnTriggerEnter as this means that your character wont actually collide with the box, you could use the Collider parameter to check to see if it really is the player which collided. However in this case I don't think there is much difference.

Comment
Add comment · Show 5 · 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 BluEye · Sep 12, 2012 at 03:14 PM 0
Share

@PProductions

That is what I thought also. Which is why I was trying the OnTriggerEnter. I did an update to my question to include the script I'm using.

avatar image PProductions · Sep 12, 2012 at 03:15 PM 0
Share

Try adding a Debug.Log statement into OnTriggerEnter to see when it is called.

avatar image BluEye · Sep 12, 2012 at 03:22 PM 0
Share

@PProductions

so would it be something like

Debug.Log ("Congratulations", finalOut (or Finalout from the layer ));

Debug.Log ("$$anonymous$$essage", "GameObject Name");

also would the Debug.Log go right before the end of the brackets or does it not matter?

avatar image PProductions · Sep 12, 2012 at 03:34 PM 0
Share

Just use: Debug.Log("Endgame triggered");

and look for the message in the console when you next test the game.

avatar image PProductions · Sep 12, 2012 at 03:43 PM 0
Share

Yes, "Endgame Triggered" is just a message: you could call it "I love ice cream" it makes no difference to the code. it's just a heads up to see which parts of your code are running.

avatar image
0

Answer by hoffmanuel · Sep 12, 2012 at 09:53 PM

You could try to use raycasts with a distance. It holds possibilities to compare tags, ...

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 Owen-Reynolds · Sep 12, 2012 at 06:03 PM

So, the script is on the exitTrigger and checks to see if it gets hit by another exitTrigger?:

 if(other.transform.gameObject.layer==9) 
 //layer nine is named finalOut and on my finalOut game object

So it isn't actually checking if it was hit by the player?

You could move the `OnTrigger` to the player, and it should work (the player doesn't need a trigger -- OTE also works if you hit a trigger.)

Or, if only the player is moving, you could skip the ifs (if something hits exitTrigger, it must be the player.) More common is to check tags. Tag the player as "Player" and:

 Debug.Log("trigger A");
 if(other.transform.CompareTag("Player")) {
   Debug.Log("Trigger B");
   // do end round stuff
 }
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 BluEye · Sep 12, 2012 at 06:50 PM 0
Share

The actual trigger script function OnTriggerEnter is attached to the GameObject.

Then Game_Controller is another script that is called at the beginning of that one. (Starting to think this wasn't a brilliant idea).

"So it isn't actually checking if it was hit by the player?" That is probably the problem as to why when I hit the GameObject nothing happens. :D

The question is. How do I fix that.

I am going to try combining and reducing the two scripts tonite to just the absolute basic of what I want.

Hit the GameObject. Box comes up, says "Congratulations" then game closes. (Seems simple enough)

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

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

Overlap point of 2 kinematic colliders 1 Answer

How do you execute Trigger-collider collision only in one gameobject? 1 Answer

How to make work a collision when is invisible? 3 Answers

Check if trigger is occupied 1 Answer

Triggering platform animation on colliding with Button 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