x


Score Workflow

When enemies collide with the player, the player's hp decreases.

When enemies collide with the player's forcefield, the player's hp increases.

Which is great! but...****

The players' score only increases from 0hp or decreases from 100hp. The player's score never increases or decreases based on the current score. A couple example's are below:

Example 1) Subtraction

The player has 100hp. The enemy hits the player for 10hp. Now the player has 90hp.

Example 2) Addition

Then the player activates a Forcefield; providing the player with 1hp every time the enemy collides with the Forcefield. Then the enemy enters the Forcefield and the player gains 1hp. Now the player has 1hp. WAIT...what???..ONE HIT POINT? Why does the player only have 1hp? The player should have 91hp, not 1hp. It just doesn't make sense.

This is because I have 2 variables assigned to the following integers: Score Variable 1 = 0, Score Variable 2 = 100

Then I convert these two integers into float variables: Float Variable 1 = 0, Float Variable 2 = 100

Now I convert Float Variable 1 to string a string called "Health". Then I enable a behavior that points to my GUIText and activates a seperate script called "Points". Then I compare the two integers Score Variable 1 and Score Variable 2. If Score Variable 1 is equal or less than Score Variable 2, you lose. Otherwise, the script starts over.

I am using the PlayMaker extension for Unity in combination with a few other scripts found elsewhere. That is why I cannot link the code, because I can't figure out how to get PlayMaker "actions" to be visible as actual compiled code from all actions. Anyway, that's why I gave the long explanation. For any of you who read this far, thank you for your time. Hopefully someone can answer it! =)

more ▼

asked Jul 20 '12 at 12:44 AM

shawnkilian gravatar image

shawnkilian
361 21 28 41

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

1 answer: sort voted first

you are adding to the variable which is set at 0, and subtracting from the var set to 100, what you want is to apply the addition or subtraction to the PLAYER'S HITPOINTS var, which will be a third var.

you start with hitpoints = 100. Then

If collide with no forcefield, simply hitpoints - 10.

now hitpoints is 90;

collide with field, hitpoints + 1. Then you could compare this hitpoints var to 0, or 100, like: if hitpoints < 0 or if hitpoints > 100

hard to be very helpful here without using code, sorry I'm not familiar with PlayMaker

EDIT(in answer to comment):

hard to say.. with a script, it would look like this:

script on the player:

var hitpoints = 100;   
var forcefield = false; //when forcefield is active,make this true

function OnCollisionEnter(other : Collider)
{
if(other.tag == "enemy"){

if(forcefield == true)
hitpoints = hitpoints + 1; // if field is active, add 1
else
hitpoints = hitpoints - 10;
  }
}

the function OnCollisionEnter gets entered automatically EVERY TIME my player's collider hits any other collider... Next, we use an "if" statement,

"if(other.tag == "enemy")"...

that way we won't take damage for bumping into every little thing, only objects we've tagged as "enemy"..

Every time you collide with an enemy, the hitpoints gets updated... Because again, the OnCollisionEnter function gets entered with EVERY collision. (same is true with triggers)

SO, if your collision damage is only happening the first time, it's a problem with the logic.

As you can see, so far there's no need for this calculation to be spread between TWO objects, it's all on the player.. As long as my enemy has a collider attached, and is tagged "enemy", this would work.

as for multiple triggers (on the same object), it doesn't work that way. The function "OnCollisionEnter" or "OnTriggerEnter" would only be used ONCE, but could contain as many actions as you need.. So you can use one trigger event to trigger multiple things..

more ▼

answered Jul 20 '12 at 07:23 AM

Seth Bergman gravatar image

Seth Bergman
7k 10 16 28

thank you Seth. I currently have it set up like that. However, I have them split between two seperate game objects. Maybe I need to keep them all on 1 object instead. Also, can you have multiple "enter" triggers or can you only put 1 on each object? I'm finding that PlayMaker ignores my commands if I put more than 1 of the same type of trigger on it. Same thing with collisions. That's the only reason I even put the scripts on 2 seperate objects (1 object has +1 script and the other has -1 script). I know it's tough to talk about with little knowledge of PlayMaker, but I do appreciate your help. Thanks again Seth.

Jul 20 '12 at 12:03 PM shawnkilian

Ok so I was able to get it to read the current score and add +1. However, when it loops back, it doesn't increase +1 anymore. It only does it 1 time. Any thoughts?

Jul 20 '12 at 03:01 PM shawnkilian

see my answer above..

Jul 20 '12 at 10:11 PM Seth Bergman

thank you Seth! I understand triggers and collisions better now. Your right about it being a problem with the logic. I moved some things around and it works now =) you have been more than helpful. big thumbs up!

Jul 20 '12 at 11:01 PM shawnkilian

glad to help!

Jul 20 '12 at 11:12 PM Seth Bergman
(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:

x3314
x271
x32
x7
x1

asked: Jul 20 '12 at 12:44 AM

Seen: 415 times

Last Updated: Jul 20 '12 at 11:12 PM