Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 finlay_morrison · Oct 29, 2017 at 04:53 PM · unity 5damageattached

How does robocraft, a unity game handle damage

So im planning a game and for my idea i require to have a damage system like in robocraft.

Firstly, this is how it works.

You have a veicle that you construct with blocks and weapons ect that you can go into battle with other players using your robot.

When a block is hit multiple times and looses all its health is is destroyed (well i think it is deactivated) however i know how to do all that.

This is the part i need help with, once a certain block is destroyed is works out weather other blocks/weapons are still attached to your robot and destroys them if not

I just dont know how i can figure out weather other blocks are still attached to the main bot.

Any help 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

2 Replies

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

Answer by luxon001 · Oct 29, 2017 at 06:20 PM

Add a "main" tag and put it on the seat or whatever the main part is. then put a tag on each block "is connected". the tag will stay if the block is connected to the main component. Use very short range raycasts on each connectable side to determine wheter it is connected (if none of those hit an object tagged(is connected) then the block falls off). If 1 raycast hits the "main" component, then its tag will be "is connected", and if a raycast hits an object tagged "is connected" its tag will also be "is connected". The tags of all block objects will be set to none after an "is connected" object is destroyed/disabled. Then start an IEnumerator function that starts with a 0.1 second delay and will disable all blocks with the "none" tag. The rays take less than 0.1s to reconfigure all the tags and as such the function is only checking which objects are left out.

This should work but may end up being buggy if 2 bots are rammed ino each other, and will always be 0.1 seconds late but you could try to reduce the time.

Hope it helps... (i might have been awfully unclear)

Comment
Add comment · Show 1 · 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 jeango · Nov 01, 2017 at 09:43 AM 0
Share

Since this was the accepted answer, let me comment on it a bit:

I wouldn't use tags, because that's not really what they are meant for, and like the poster said, if two robots are really close to each other you'll have bugs.

Ins$$anonymous$$d you should use a component (ConnectionStatus or something like that) that has two public fields

 public bool isConnected; // connection status
 public GameObject Robot; // the robot to which this block is connected

Then when a block is destroyed, when you do your raycast you can do a GetComponent and check if the blocks hit by that raycast are connected and belong to the same robot

avatar image
0

Answer by jeango · Oct 29, 2017 at 06:29 PM

You could have a hierarchy of blocks so that when you killed a block all its children are automatically destroyed with it.

If you don't want to use Unity's built in hierarchy (in the case for example of multiple parents, or of you don't want the transforms to be moved together) you could do something like this:

 public class Block : MonoBehaviour {
 
     public List<Block> children;
     public List<Block> parents;
 
     // use this to add child/parent relationship between objects
     void AddChild(Block child) {
         children.Add (child);
         child.parents.Add (this);
     }
 
     // use this when your block's health drops to 0
     void DestroyBlock() {
         foreach (var item in children) {
             item.RemoveParent (this);
         }
         Destroy (gameObject);
     }
 
     // destroys the block if he has no more parents
     public void RemoveParent(Block parent) {
         if (parents.Remove (parent)) {
             if (parents.Count == 0)
                 DestroyBlock ();
         }
     }
         
 }
Comment
Add comment · Show 7 · 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 luxon001 · Oct 29, 2017 at 06:35 PM 0
Share

that would only work if the objects were pipe-like and have only 2 connectable sides... Because with 6 sided cubes the hierarchy parent-child would be incredibly messed up and buggy...

avatar image jeango · Oct 29, 2017 at 07:33 PM 0
Share

you don’t necessarily have to use the built-in hierarchy. Each object could have an array of “children” blocks and when you destroy an object you just call destroy On all objects in the array which in turn will call destroy on their own children etc

avatar image jeango · Oct 29, 2017 at 07:37 PM 0
Share

Unless you mean that an object can have multiple parents.in that case I will also add an array of parent blocks To each block. So when a block is destroyed It informs his children then the children Remove that lock from their parents list and if after that the list is empty they destroy themselves

avatar image luxon001 · Oct 29, 2017 at 07:52 PM 0
Share

but each object will be connected to a bunch of other objects, meaning that each child object will be a "child" of other objects and it simply wouldnt work.

avatar image jeango luxon001 · Oct 29, 2017 at 07:59 PM 0
Share

With the code I provided, whenever you add a block it will be connected to a certain number of already existing blocks (except the very first one, which would then be the "Core" of your robot). Just call AddChild on each of those connected blocks, and it should work like a charm.

avatar image luxon001 · Oct 29, 2017 at 08:27 PM 0
Share

ok i understand now that you published the code, makes sense.

avatar image jeango luxon001 · Oct 29, 2017 at 09:03 PM 0
Share

If it works for you, don't hesitate to accept my answer, could help people with the same problem.

You may want to re-phrase your original question, however, because it's not really about damage.

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

146 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[Help!]Unity FPS Health script error. 1 Answer

Urgent help for Unity Game with deadline tomorrow 0 Answers

UNET sending/recieving damage 0 Answers

MoveCreatures() Method crashes unity HELP 0 Answers

Replace the network manager hud with my own UI elements 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