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
1
Question by CallToAdventure · May 03, 2011 at 02:25 PM · damagehealth

Damage/Health problem

All right, I've been looking and testing all sorts of examples and answers, the problem is simple yet I fail to get it right.

I have a small prop (a barrel) and I want to shoot it with a projectile and kill it after 2 hits (for the arguments' sake)

Now, for the prop I have this from the fps example:

var hitPoints = 100.0; var detonationDelay = 0.0; var deadReplacement : GameObject;

function ApplyDamage (damage : float) {

 if (hitPoints <= 0.0)
     return;

 hitPoints -= damage;
 if (hitPoints <= 0.0) {

 Invoke("DelayedDetonate", detonationDelay);
 }

}

function DelayedDetonate () { BroadcastMessage ("Detonate"); }

function Detonate () {

 Destroy(gameObject);


 if (deadReplacement) {
     var dead : GameObject = Instantiate(deadReplacement, transform.position, transform.rotation);
 }

}

and for the projectile, this:

var explosion : GameObject;

function OnCollisionEnter( collision : Collision ){ var contact : ContactPoint = collision.contacts[0]; var rotation = Quaternion.FromToRotation( Vector3.up, contact.normal ); var instantiatedExplosion : GameObject = Instantiate(explosion, contact.point, rotation ); if (collision.gameObject.tag=="PreciousWreckageBarrels") SendMessage("ApplyDamage",5.0,SendMessageOptions.DontRequireReceiver); } function FixedUpdate () { rigidbody.AddForce (transform.TransformDirection (Vector3.forward) * 6000.0); }

Tagged the prop correctly, did everything in my humble powers. Should I stop scripting? :)

Any help, greatly appreciated.

Comment
Add comment · Show 2
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 FLASHDENMARK · May 03, 2011 at 02:30 PM 0
Share

Laughed at Should I stop scripting?.

avatar image Jean-Fabre · May 03, 2011 at 02:33 PM 0
Share

me too :) and still do...

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jean-Fabre · May 03, 2011 at 02:42 PM

Ok,

Not sure exactly where is the problem, but the best answer is to give you some hints on how you can find the problem:

1: either in the debugger or with some good old Debug.Log("hello"). try to progress through the system.

-- do you reach OnCollisionEnter ( that is if you put Debug.Log("hello") as the first instruction in OnCollisionEnter and you do get it in the console when you see the projectile hit your object)

-- if yes, do you reach ApplyDamage() ?

-- if yes, does hitPoints get properly set?

-- if yes, do you reach DelayedDetonate ?

-- if yes, then all is fine

By doing so, you'll be able to locate the source of your problem accuratly.

Else, can you explain what exactly is not working?

Bye,

Jean

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 Rabwin · May 03, 2011 at 02:51 PM

First of all, it doesn't need to be a broadcast, otherwise you might end up blowing up other barrels too. You should be using something like the following:

this.sendmessage("Detonate");

better

Detonate();

Also, does it really need 6000 force? Your scene scale must be huge O.o

IMO the object is moving so fast, it actually goes through the barrel on each frame. I reccomend doing a Debug.Log("something") at each section to find out whos the culprit.

Good luck!

EDIT: lol jean beat me to it.

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

No one has followed this question yet.

Related Questions

Health and Damage [C#] 2 Answers

Need Help With Simple Player Health Damage Script 1 Answer

How do I destroy a game object (The enemy Goblin Game Object) upon entering a collision box? (JavaScript) 2 Answers

Damage Indicator not showing correct position of attack. 0 Answers

Where can I find the scripts used in the Player State Machine & HUD/GUI Tutorials? 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