Thought I had this solved by adding in hit sensors, been stumped for the past few days.
Problem: When two player units attack an enemy unit the enemy unit's health drops by 13-17 points when it's only supposed to drop by 2 (one for each player hit).
If their animations are staggered the health subtraction works perfectly.
Here is my capx:
I have it set to spawn two player units with one click of the buy button to simulate when they get stacked up after defeating an enemy unit together, hopefully someone can help!
(Mouse over the enemy unit to see it's health)
I imagine you are subtracting the health in an event that is occurring "every tick" instead of just once.
Try adding a "trigger once while true" as a condition to the event that subtracts the health.
Sorry i can't look at the capx right this moment.
Develop games in your browser. Powerful, performant & highly capable.
I do, that is what baffles me. Why the stacked animation causes the problem. 1 vs 1 works, 2 vs 1 when the attack animations are on different frames also works, but if they end up attacking on the same frame then the health of the enemy drops by a large portion.
Here is the code for health subtraction if that helps without looking at the capx.
<img src="http://i702.photobucket.com/albums/ww22/fishtank36/c2events.jpg" border="0" />
I'm fiddling about with this at the moment - quick question: If you spawn two playerUnits and one enemyUnit, should the one enemyUnit stop both playerUnits or just one of them?
It should stop both of them, it's a prototype for setting up a side-view base defense game, so to get to the other base I wanted both sides to go through (kill) one another before proceeding.
Also I forgot to mention that the way the current health subtraction is set up is supposed to pick the nearest enemy to the hitbox and subtract that enemies health, so if it's 2 vs. 1 - the single unit won't be able to fend off both at the same time.
I think there were a few issues together which were causing the problem. I refactored some of your capx and it seems to be working now:
1) If I've completely misunderstood what you are trying to do, let me know <img src="smileys/smiley1.gif" border="0" align="middle">
2) I've only fixed the player sprites for now. Assuming I understood the post correctly it should be fairly easy to update the enemy AI.
Hopefully, if I got it right, this helps in some way <img src="smileys/smiley12.gif" border="0" align="middle">
Thank you! I really appreciate this, it's hard to know and learn how to create these conditions properly and without creating a whole bunch of extra work (like overlap instead of comparing range).
I do have two questions if you don't mind:
1) How would I go about re-implementing the feature where one player can only attack one enemy unit at a time? In my capx the only way I could get it to work was by adding the pick closest enemyunit to hitsensor. As you noted this reiterates construct already picking an enemyunit, but if two enemy units overlap the hitsensor they do both take damage. (Event 33 in your capx)
If the player spawn is set to only one unit and you spawn two enemy units the player can hit both of them at the same time.
2) Event 34 (every X seconds -> destroy hitsensor) Is there a better way to destroy the stray hitsensors? Or does your event system for attacking prevent this? With mine sometimes the enemy would die just before the hitsensor spawned leaving an extra hitsensor on the layout. This is just in case in future testing.
Thank you again for your time!
1) Ah good point. So I think what's happening is that the pick nearest is only selecting one single enemy (which is good), but then spawning a hit sensor that is overlapping both enemies (which is bad).
Download V2 Capx
What this is now doing is spawning a hit sensor, but we are recording the UID (a unique ID that Construct assigns to every object) to it's instance variable. You can then use the "Pick by unique ID" to ensure that, when a sensor is overlapping the enemy, it only picks the one with the ID that we assigned to it.
2) I noticed that a few times myself. The reason it's happening is because it's saying only if the hit sensor is overlapping the enemy, then apply damage and destroy it. If the enemy is destroyed before this event is run (in the case of two players attacking one enemy), the second hit sensor is never destroyed because the enemy is already dead. To get around this I think you can add a condition at line 29 that when an enemy dies, any hit sensors that are overlapping it are also destroyed.
<img src="https://dl.dropbox.com/u/20830426/rtsFixesScreens/question2.png" border="0">
Combined with the first note above, this screenshot is a little out of date (since we are now only destroying hit sensors assigned to the enemy), but you get the idea.
Hope this helps. You've done an impressive amount of work so far already, it's looking to be a really cool game <img src="smileys/smiley1.gif" border="0" align="middle">
Thank you again! I am learning a lot from this, going to add more enemies and players using your event system :)