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 MikezNesh · Jul 13, 2010 at 11:17 PM · aidamage

Setting up smart damage taking in game...

I'm trying to set up a game like Phage Wars.

In that game when your troops collide they either support (if it's your building) or attack (if it's the enemies building) the buildings.

I want to know how to set up a way to tell whether to add or subtract to the number of people when a soldier collides a building. How would I do that?

(This depends on whether you control or they control the building and which team the soldier is on).

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
1
Best Answer

Answer by Peter G · Jul 14, 2010 at 12:41 AM

I would have either tags or variables for each group, then on collision, check to see if the soldiers tag matches the building's tag and if it does then send a message to the building to add defenses and hide the soldier. Otherwise, send the soldier into attack mode.

A similar and easy way would be to make an enum for the different groups, give every object a script which decides that enum i.e. red team, blue team... then use GetComponent to grab that script, compare the enum of the soldier and the building and check to see if they match. This would be helpful if you were using tags for something else already.

ex.

//This script goes on the player. function OnCollisionEnter(col : Collision) { if(col.gameObject.CompareTag(this.tag)) { col.gameObject.BroadCastMessage("AddReinforcments", SendMessageOptions.DontRequireReceiver); HideSoldier(); }

  else {
     Attack(col.gameObject);
  }

}

function HideSoldier () { renderer.enabled = false; }

function Attack (target : GameObject) { //attack the gameObject; } //Didn't test it. Check for typos.

Comment
Add comment · Show 10 · 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 MikezNesh · Jul 14, 2010 at 01:01 AM 0
Share

what does "enum" mean?

avatar image MikezNesh · Jul 14, 2010 at 01:03 AM 0
Share

Do I need to change "this.tag"?

avatar image Peter G · Jul 14, 2010 at 01:33 AM 0
Share

See http://msdn.microsoft.com/en-us/library/sbbt4032(VS.80).aspx for info on enumerations. They look very similar in JS. enum Team{Blue, Red}; I think. I can't quite remember how to do them in JS. They create like a multiple choice where the value can be one of the selected. You shouldn't need to change this.tag. You have to remember that "this" is a monobehaviour which is a type of component. Components have a tag variable so this.tag is saying thisComponent.tag .

avatar image Peter G · Jul 14, 2010 at 01:36 AM 0
Share

Edit. I think the pickup item script in the lerpz tutorial shows how to use enums in js. the enum is something like enum Pickup{health, fuelcell}; Edit 2: In my oppinion, $$anonymous$$SND gives way more information than they have to and it can be very intimidating. I would also recommend searching the term on the internet and getting a simpler idea because you don't need a very in-depth knowledge for what you are doing.

avatar image MikezNesh · Jul 14, 2010 at 02:12 AM 0
Share

I got an error.... what does this mean? "Actor::update$$anonymous$$assFromShapes: Compute mesh inertia tensor failed for one of the actor's mesh shapes! Please change mesh geometry or supply a tensor manually!"

Show more comments
avatar image
1

Answer by Callum McIntyre · Jul 13, 2010 at 11:38 PM

You would use a standard collision script to detect collisions - if you haven't got that in place yet, I suggest you search it.

You'd then have an if statement inside the function called on any soldier-building collision.

You'd check if the building collider is owned by you or the enemy - you'll have to set a variable each time a building is captured.

If it's yours the soldier will run a function to add to the variable, if it's the enemies you'd run a function to subtract from it.

The difficult bit is the collision detection, and that's not something I'm good with. I'd suggest you search it, or run through the tutorials which explain it very well.

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 MikezNesh · Jul 14, 2010 at 12:24 AM 0
Share

Well I already made this list myself in my head. The question was more how would I do it in script.... Thanks for the effort though. If you put it in code you will get a Checkmark and an Upvote but for now only and UpVote. If you add code I will give Checkmark :P! Again, Thanks for effort.

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

My rockets don't do damage? 1 Answer

Bootcamp damage 0 Answers

AI Damage if touched 1 Answer

FPS Tutorial AI Damage not Working 1 Answer

The enemy don´t lose health, but why??? 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