x


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).

more ▼

asked Jul 13 '10 at 11:17 PM

MikezNesh gravatar image

MikezNesh
843 64 74 93

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.
more ▼

answered Jul 14 '10 at 12:41 AM

Peter G gravatar image

Peter G
15.1k 16 44 137

what does "enum" mean?

Jul 14 '10 at 01:01 AM MikezNesh

Do I need to change "this.tag"?

Jul 14 '10 at 01:03 AM MikezNesh

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 .

Jul 14 '10 at 01:33 AM Peter G

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, MSND 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.

Jul 14 '10 at 01:36 AM Peter G

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

Jul 14 '10 at 02:12 AM MikezNesh
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jul 13 '10 at 11:38 PM

Callum McIntyre gravatar image

Callum McIntyre
32 5 5 10

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.

Jul 14 '10 at 12:24 AM MikezNesh
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x960
x249

asked: Jul 13 '10 at 11:17 PM

Seen: 1075 times

Last Updated: Jul 13 '10 at 11:17 PM