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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Adhordal · Apr 07, 2015 at 01:02 AM · javascriptraycastcolliderparticlesystemflamethrower

Applying damage with Flamethrower-like weapon

The weapon is actually a hand which shoots fire (much like in Skyrim). My first attempt at applying damage was through the Particle Collision, with the Send Collision Messages. This looked pretty much what i was looking for, but more testing surfaced a problem: The damage caused by the particles varied a lot and was influenced by fps, which was sub-optimal. My next attempt was with a box in the hand extending to the range limit (no mesh renderer) with a box collider. It applied damage to the enemies just like I wanted it to and was stable, but the problem was that if two(or more) enemies were in a straight line, it would damage both, which makes no sense as the flame stops at the first one. The third attempt was with raycast. This was perfect, except for the fact that it casted only one ray, in a straight line like a gun. The flame is fairly wide. This method made shooting flames a matter of aiming down. Also I failed in combining the 2nd and 3rd option. I then returned to the first option and the same problems plague me.

 function throwFlame(rast : boolean)
 {    
 
     if(PlayerStats.GetWill() > 0)
     {
         damageCollider.SetActive(rast);
 //        var flameHit : RaycastHit;
 //        var fwd = flame.transform.TransformDirection (Vector3.forward);
         PlayerStats.AddWill(-damageFireCost / 10);
 //        if(Physics.Raycast(flame.transform.position, fwd, flameHit, 5))
 //        {        
             if(enemyCol != null && enemyCol.transform.tag == "Enemy")
             {
                 if(enemyCol.GetComponent.<ParticleSystem>() != null)
                 {
                     enemyCol.GetComponent.<ParticleSystem>().enableEmission = true;
                 }
                 //    var AIEnemy : Component;
                 //    AIEnemy = enemyCol.GetComponent("AIEnemy");
                 //    if(AIEnemy != null)
                 //    AIEnemy.AddHealth(-20 * Time.deltaTime);
                 
             }
             flame.GetComponent.<ParticleSystem>().enableEmission = rast;
         }
         else
         {
                 flame.GetComponent.<ParticleSystem>().enableEmission = false;
                 flame.GetComponent.<ParticleSystem>().Clear();    
         }
 }

Above is the script on my player. The commented parts are leftovers from my previous attempts.

Below is the script on the enemy that registers the damage:

     void OnParticleCollision (GameObject other)
     {
         if (other.transform.tag == "ParticleFireShoot") {
             health -= 2;
         }
     }

Thank you, any input is appreciated.

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

Answer by contact_unity364 · Jan 26, 2021 at 11:53 PM

The approach which I will use, is to get a list of enemies who are in front of the player, and within range of the flames. then work out the angle difference between your fire start point / forward vector and the enemy colliders. Then you have a distance and angle so you could work out some proportional damage based on those. I.e. directly infront and close would get hit by a lot of fire, where as further away and off to the side would get less. And cut off at ~15%.

If it was an issue, you could help out performance by maintaining a list of enemies who are roughly in proximity and only update that list every 1/3 of a second, and then only check the angle and distance every 1/6 second or something like that.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to use a Raycast to see the distance traveled within a collider. 2 Answers

Move player to specific location and avoid obstacle. 2 Answers

Im trying to create a word game with a twist 0 Answers

Raycast not detecting ANY HITS AT ALL when starting inside a collider. 0 Answers

ball sometimes goes through the bat when hit... collider problem... How to do a Raycast? 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