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 01:03 PM · javascriptraycastvector3damagefalling

Fall Damage Script Problem?

Hello! So i have my first person controller up in the air on a cube in order to test this kind of Fall Damage script. You know as soon as the player hits the ground i want to see the message "Take Damage!" in the console. The issue here is that as soon as i hit play i get spammed by this message even when i am up on the cube. This is the script i use:

function Update(){

 var up = transform.TransformDirection(Vector3.up);
 
 if(Physics.Raycast(transform.position, -up, 10)){
 
     Debug.Log("Take Damage!");
 }

}

Comment
Add comment · Show 1
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 01:04 PM 0
Share

Of course later i'll make it so that the player has some actual healt but for now let's do the actual fall damage thingy :P

1 Reply

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

Answer by MrSteve1 · Apr 19, 2013 at 01:20 PM

For that I wouldn't bother with Raycasting, I would use :

 function OnCollisionEnter(hit : Collision)
     {
          if(hit.gameObject.tag == ("Floor")
               Debug.Log("Take Damage");
     }

This will do it each timer you hit any object you tag "Floor"

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

Thanks! Theoretically, that should work. However, i just used it and i don't see any message from the console :( Is it because i use a Plane tagged "Floor" as my floor? But even planes are considered gameobjects right?

avatar image WesterlyCarrot9 · Apr 19, 2013 at 01:35 PM 0
Share

Also, wouldn't that be confusing a bit later on? Simply because the player won't be up in the air all the time and will have to walk on the floor too. I'm pretty new to Unity3D so please excuse those stupid questions of $$anonymous$$e :P

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

12 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

Related Questions

i don't understand Vector3.forward correctly on camera 1 Answer

How to damage gameobject via raycast 1 Answer

having problems with my raycast shooting script 0 Answers

How can I decrease accuracy when the gun is fired? 2 Answers

Networked 3rd person aiming 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