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 OscarBrooks · Aug 31, 2013 at 09:55 PM · rigidbodytriggerplayervelocity

Player Collide with Fast moving Rigidbody to cause Death?

I was wondering If anybody could help me;

I need to know how i would go about making a player die if it gets hit by a fast moving Rigidbody. I need the script and the collider trigger to be attached to the player, so i dont know how i could check that the velocity of the rigidbody is enough to kill the player.

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

1 Reply

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

Answer by DESTRUKTORR · Aug 31, 2013 at 10:01 PM

 // C# version
 void OnCollisionEnter(Collision col)
 {
      if(col.relativeVelocity > someValue)// where "someValue" is a variable of your choosing.
      {
           killPlayer();// You'll have to implement how the player will die, yourself, but just call the method(s) needed to kill them, here.
      }
 }

Or, if you use JavaScript

 // JavaScript version
 function OnCollisionEnter(collision : Collision)
 {
      if(col.relativeVelocity > someValue)// where "someValue" is a variable of your choosing.
      {
           killPlayer();// You'll have to implement how the player will die, yourself, but just call the function(s) needed to kill them, here.
      }
 }

Put one of these in a script on your character (choose whichever you like. Both do the same thing).

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 OscarBrooks · Aug 31, 2013 at 10:16 PM 0
Share

Hey, thanks for answering. I think you are right, but I get an error message saying "$$anonymous$$ identifier: col". do you know what is happening, or what to replace "col" with?

avatar image OscarBrooks · Aug 31, 2013 at 10:48 PM 0
Share

Okay, I think I fixed my problem, but when I run my game, nothing happens when the player is hit. Do you know what the problem could be?

avatar image DESTRUKTORR · Sep 01, 2013 at 06:27 PM 0
Share

What does your kill method look like? Also, try putting this:

 Debug.Log("It's registering the hit");

in that method, just after the call to killPlayer(); If it is registering the collision, it will print "It's registering the hit" to the console. If not, it won't, and you'll have found the problem (though it may not be the source of the problem, it is definitely a step in the right direction).

If it does print that, then the issue is likely with your kill method.

avatar image OscarBrooks · Sep 01, 2013 at 06:43 PM 0
Share

When I said nothing happens I meant that Debug.Log("You are Dead") didn't show up. It's all good now though, I fixed it. Thanks for your first answer!

avatar image DESTRUKTORR · Sep 01, 2013 at 07:30 PM 0
Share

No problem XD it's why I frequent this site, haha!

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

17 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

Related Questions

rigidbody.velocity not working on x axis 2 Answers

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

Rigidbody player movement unrealistic velocity problem. 1 Answer

How to slow player on x and z 1 Answer

Addforce up to kenemetic rigidbody of the triggerobject player 2 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