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 acsended · Nov 11, 2011 at 02:06 PM · aidamagerocket

Ai Aint Taking Damage From Bullet (FPS Rocket)

hello guys my english isn't that good but im doing my best to explain my problem as best as i can so for start i have 2 scripts the damage reciever and the rocket script both from the fps tutorial well i edited the rocket script a little bit so i would get rid off the explosion area damage and just do damage on hit/collide so i can use it for my ak-47 but it doesn't does any damage and i dont get errors or anything and im stuck on this for about 3 days before those 3 days every bullet with the ak-47 was a one shot kill even if i put the damage to 0 well il show the scripts

THE ROCKET SCRIPT

 var explosion : GameObject;
 var timeOut = 3.0;
 var damage = 10;
 
 function Start () {
 
 Invoke("Kill", timeOut);
 
 }
 
 function OnCollison (hit :Collision) {
     
     
 // Tell the object you hit that it was damaged
 
     hit.CharacterController.SendMessageUpwards("ApplyDamage", damage,SendMessageOptions.DontRequireReceiver);
 
     // And kill our selves
     
 Kill ();
   
 }
 function Kill () {
     // Stop emitting particles in any children
     var emitter : ParticleEmitter= GetComponentInChildren(ParticleEmitter);
     if (emitter)
         emitter.emit = false;
 
     // Detach children - We do this to detach the trail rendererer which should be set up to auto destruct
     transform.DetachChildren();
         
     // Destroy the projectile
     Destroy(gameObject);
 }
 
 
 @script RequireComponent (Rigidbody)
 
 ------------------------------------------------------------
 
 THE DAMAGERECIEVER SCRIPT
 
 
     var hitPoints = 100.0;
 
 var detonationDelay = 0.0;
 
 var explosion : Transform;
 
 var deadReplacement : Rigidbody;
 
 
 
 function ApplyDamage (damage : float) {
 
 
 
     // We already have less than 0 hitpoints, maybe we got killed already?
 
     if (hitPoints <= 0.0)
 
        return;
 
        
 
        
 
     hitPoints -= damage;
 
     
 
     if (hitPoints <= 0.0) {
 
        // Start emitting particles
 
        var emitter : ParticleEmitter = GetComponentInChildren(ParticleEmitter);
 
        if (emitter)
 
          emitter.emit = true;
 
 
 
        Invoke("DelayedDetonate", detonationDelay);
 
     }
 
 }
 
 
 
 function DelayedDetonate () {
 
     BroadcastMessage ("Detonate");
 
 }
 
 
 
 function Detonate () {
 
     // Destroy ourselves
 
     Destroy(gameObject);
 
 
 
     // Create the explosion
 
     if (explosion)
 
        Instantiate (explosion, transform.position, transform.rotation);
 
 
 
     // If we have a dead barrel then replace ourselves with it!
 
     if (deadReplacement) {
 
        var dead : Rigidbody = Instantiate(deadReplacement, transform.position, transform.rotation);
 
 
 
        // For better effect we assign the same velocity to the exploded barrel
 
        dead.rigidbody.velocity = rigidbody.velocity;
 
        dead.angularVelocity = rigidbody.angularVelocity;
 
     }
 
 
 
     // If there is a particle emitter stop emitting and detach so it doesnt get destroyed
 
     // right away
 
     var emitter : ParticleEmitter = GetComponentInChildren(ParticleEmitter);
 
     if (emitter) {
 
        emitter.emit = false;
 
        emitter.transform.parent = null;
 
     }
 
 }
 
 
 
 // We require the barrel to be a rigidbody, so that it can do nice physics
 
 @script RequireComponent (Rigidbody)


i think the problem is in the rocket script i think the function call of ApplyDamage isn't going good and the weird thing is the real rocket script with area damage and everything works fine i just need the bullet to on hit call function applydamage in the damagereciever and the best thing would be if i can edit the damage in the bullet (rocket script) by a var i tried a bunch of different codes and i just didnt managet to get it fixed

so after 3 days im gonna ask the pro's hope u guys can help me

Comment
Add comment · Show 5
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 acsended · Nov 14, 2011 at 10:06 AM 0
Share

guys guys can no one help me ? or is it to difficult but a little help would be great

avatar image FLASHDENMARK · Nov 14, 2011 at 10:59 AM 0
Share

I did not read the hole thing but you have a function called " OnCollison" there is no built in function named that. You should properly change it to "OnCollisionEnter(hit : Collision)

avatar image acsended · Nov 14, 2011 at 03:40 PM 0
Share

already tried didnt work i thought with oncollisionenter it's about the bullet that needs to enter the collider so oncollision just on touch but both didnt work

avatar image acsended · Nov 16, 2011 at 11:45 AM 0
Share

i already fixed it with total other script this one was driving me insane but i liked it more because there were real bullets

avatar image sacredgeometry · Nov 16, 2011 at 11:52 PM 0
Share

I didnt read it but if its what i think you were trying to do then you cant use colliders for bullets that are at anywhere near bullet speed because in the smallest unity of testing (ie a frame) the bullet could have essentially teleported past the object you were ai$$anonymous$$g at.

best to use bullets for visual and raycasting for the mechanics.

1 Reply

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

Answer by aldonaletto · Nov 17, 2011 at 12:36 AM

This line is wrong:

 hit.CharacterController.SendMessageUpwards("ApplyDamage", damage,SendMessageOptions.DontRequireReceiver);

hit is a Collision, and it doesn't have a CharacterController field. You could try this:

 hit.transform.SendMessageUpwards("ApplyDamage", damage,SendMessageOptions.DontRequireReceiver);

You should also use CharacterDamage.js to receive damage in CharacterControllers - DamageReceiver.js is intended to be used with rigidbodies, and will produce runtime errors. Another thing: weapons with fast bullets like guns and rifles should use Raycast to shoot (fast projectiles often are not detected) - take a look at the MachineGun.js script.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Ai that applies damage in collision? 1 Answer

Damage trigger? 1 Answer

My rockets don't do damage? 1 Answer

Area of effect melee attack for 3rd person game? 1 Answer

FPS Tutorial AI Damage not Working 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