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 SHBelsky · Jul 24, 2013 at 03:40 PM · javascriptcollisionloadlevelapplication

Collisions not working.

I am working on a small game that uses a "game over" screen that is displayed upon a collision with a pit (a cube with black material.) The cube itself has a rigidbody and box collider.

This is the script (Javascript) attached to my player (First Person Controller Camera, has a RigidBody and Capsule Collider with no trigger.)

 function OnCollisionEnter(deadPlayer : Collision)
 {
     if (deadPlayer.gameObject.tag == "Pit")
     {
         Destroy (gameObject);
         Application.LoadLevel("deathPit");
     }
 }

The player properly collides with the cube, rather, it acts as a floor. But the level specified in the last line is not loaded, and I stay in the bottom of the pit until I exit the game.

Any help would be appreciated. :c

Comment
Add comment · Show 7
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 zombience · Jul 24, 2013 at 03:59 PM 0
Share

does the player get destroyed? are you sure the "if" statement is correctly executed?

avatar image SHBelsky · Jul 24, 2013 at 05:59 PM 0
Share

The player doesn't get destroyed. It just stays on the cube as if it's a floor; nothing happens.

avatar image Tatsunomi · Jul 24, 2013 at 06:06 PM 0
Share

Did you forget to tag your player object inside the inspector? Try to tag your object with $$anonymous$$ on the inspector window while your player object is selected.

avatar image SHBelsky · Jul 24, 2013 at 06:07 PM 0
Share

The player is tagged as "Player" and the pit is tagged as "$$anonymous$$".

avatar image Dave-Carlile · Jul 24, 2013 at 06:12 PM 2
Share

Debug.Log is your friend. Log messages right after you enter OnCollisionEnter, log the value of the tag, and so on. Do you get the first log message? If not then the collision isn't being detected for some reason - probably some colliders not configured correctly. What does the tag display as? The comparison is case sensitive, so make sure it's "$$anonymous$$", not "pit", etc...

 function OnCollisionEnter(deadPlayer : Collision)
 {
   Debug.Log("Collision");
   Debug.Log("tag=" + deadPlayer.gameObject.tag));
   if (deadPlayer.gameObject.tag == "$$anonymous$$")
   {
     Debug.Log("Found pit");
     ...
   }
   else
   {
     Debug.Log("Didn't find pit");
   }
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tatsunomi · Jul 24, 2013 at 06:35 PM

Try Placing this script on your Pit Object... See if this works

 function OnCollisionEnter(deadPlayer : Collision)
 {
     if (deadPlayer.gameObject.tag == "Player")
     {
         Debug.Log("HIT");
        Destroy(GameObject.FindGameObjectWithTag("Player"));
        Application.LoadLevel("death");
     }
 }

Depending on where you placed the script I decided to place this in the GameObject tagged Pit so when the other object tagged "Player" hits "pit". The "Player" gameobject will be destroyed and the level will be loaded.

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

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

Related Questions

How to create a complicated game over scene ? Help 1 Answer

Analysing player metrics help 0 Answers

Can someone help me with my script? 0 Answers

Collision no longer occurs after turning off shield (javascript) 1 Answer

How to add to a 3D object's length through code? 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