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 WesterlyCarrot9 · Apr 19, 2013 at 02:27 PM · javascriptcollisionphysicsfallingfloor

Fall Damage OnCollisionEnter Script Help.

Ok so a very good person in the community helped me with an issue i had about falling damage and gave me the script you can see below. The thing is it doesn't seem to work. I used a rigidbody for one of the colliders since this is an OnCollisionEnter but still nothing. The scene i am working right now has the first person controller on a cube up in the air and i want him to take damage as soon as he hits the ground. For some reason the Plane is use for the floor won't take the rigidbody and the test cube i used as my floor won't work with the script. Any help?

Here is the script:

function OnCollisionEnter(hit : Collision){

 if(hit.gameObject.tag == ("Floor"))
     Debug.Log("Take Damage");

}

Comment
Add comment · Show 8
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 WesterlyCarrot9 · Apr 19, 2013 at 02:30 PM 0
Share

Of course, the player won't be up in the air all the time. He will be able to walk on the floor too so is it possible to not be confused by this?

avatar image pudd1nG · Apr 19, 2013 at 02:50 PM 0
Share

Try removing the brackets around "Floor"

avatar image WesterlyCarrot9 · Apr 19, 2013 at 02:55 PM 0
Share

I'm afraid i can't do that. I get the usual error $$anonymous$$ identifier. We always have to use brackets :)

avatar image Loius · Apr 19, 2013 at 03:23 PM 0
Share

You can't just make up a tag in script. It has to already exist in the project settings and your floor has to be tagged it.

Also check the collision table near the bottom of http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html

avatar image WesterlyCarrot9 · Apr 19, 2013 at 03:26 PM 0
Share

Of course i have created the tag before testing it!

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by dendens2 · Apr 20, 2013 at 02:39 PM

 if(hit.gameObject.tag == ("Floor"))
     Debug.Log("Take Damage");

What you did wrong is that the gameObject does not store the collision (At least that is what I think, lol). It is the collider. I think it should be this.

 if(hit.collider.tag == ("Floor"))
     Debug.Log("Take Damage");

I am pretty sure you can remove the brackets too.

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 dendens2 · Apr 20, 2013 at 02:42 PM 0
Share

It might be .transform.tag too.

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

14 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

Related Questions

How do I "remove/disable" collision? 3 Answers

Raycast to Terrain (Conditional Statements) 1 Answer

Collision not working 1 Answer

Detecting Collision points of particles? 1 Answer

Check if layers can collide 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