Help with player life/health

Hello all,

I'm making a simple game that involves a player flying through space (top-down) where the player must shoot incoming asteroids, and pick up power-ups.

When an asteroid is hit by either a bullet or the player, the asteroid explodes using particles. I do this by hiding the asteroid and spawning particles, then destroying the asteroid 0.5 seconds later (it looks great). However, here is my problem: when the player hits an asteroid once, player health indeed diminishes by 1. But when the player collides with a second asteroid, nothing happens.

Here is the logic behind the game that relates to this issue:

PLAYER
-when player overlaps or collides with actor with tag "Asteroids" then change attribute game.PlayerHealth to game.PlayerHealth-1. Seems simple enough.

Asteroids
-Change attribute self.tags to Asteroids
-When actor overlaps or collides with actor with tag "Player" AND self.tags = Asteroids, then change attribute self.color.alpha to 0, change self.tags to null, spawn particles, and after 0.5 seconds destroy actor.

From the above logic, an asteroid spawns at the top of the screen with the tag "Asteroids" and hits the player and explodes. The player should lose 1 health every time this occurs, but it only happens the FIRST time it occurs. I have tested the status of the asteroid tags by making a rule: If self.tags = Asteroids, change attribute self.height to 120. This makes the asteroid spawn looking like a long stick, and proves that the tag is indeed starting at "Asteroids".

In addition, the rules state that the asteroids would not even explode on contact with the player if the tag was not "Asteroids". This leads me to think that the programming with the player is the problem and the lives/health is not counting down properly. I am using a simple Display Text that displays game.PlayerHealth.

Please advise me on how to fix this. Any help is much appreciated, thank you.

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    The problem is that if the player collides with two or more asteroids at once, the collision rule won't trigger again after the first collision since it's already true.

    Remove the collision rule from the player and put it in the asteroid actor.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • Okay, I'll try this when I'm back on my computer. Thank you so much. I will make sure to check "answered" if this does work.

  • t.henstrand@gmail.comt.henstrand@gmail.com Member Posts: 14
    edited March 2014

    This solution doesn't work. I turned off the collision rule on the player and have added a [If asteroidsmall collides with player AND self.tags=Asteroids, then set game.PlayerHealth to game.PlayerHealth-1]
    Nothing happens with this rule. I have no idea what's going on with this.

    Furthermore, my testing revolves around me colliding only with "asteroidsmall". My collisions are one at a time so the logic that I'm hitting more than one asteroid at a time. I cannot be hitting more than one asteroid at any given time.

    Edit: I thought of a round-about way of making the health work, which involves adding an integer called "numberOfAsteroidsHit". I can set the health based on how many asteroids the player has hit... Seems like a bad way of doing it though...

    Does anyone else have a solution to my problem?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    I'm not sure why you have self.tags in the rule condition but regardless, what may be happening is that the invisible asteroids actor that hangs around for 0.5 seconds is still triggering the collision rule and therefore another asteroid isn't counted as a collision. Try spawning a separate actor with the particles behavior instead of having that behavior within the asteroid actor itself.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • I can't spawn a separate actor for the particles because the speed and direction the each asteroid is moving in is randomized. Also, I have self.tags in the rule, otherwise the player would be able to hit the invisible asteroids. As of now, all asteroids spawn with tag "Asteroids" and have their tag changed to "null" when shot or being crashed into by the player.

    Previously, I had the logic as "when player collides with SmallAsteroid, MediumAsteroid, etc., then reduce health by one". This doesn't work, because the "null" asteroids were still triggering the event. I need the tags here. What's puzzling is that I can make rules based on the asteroid tags being "Asteroids" or "null" and they work. But for some reason only the first collision with an asteroid will reduce health, from then on, nothing happens.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Here's a demo that shows how collisions and attribute decreasing should work: https://www.dropbox.com/s/4no7h8xwci75tye/asteroid collision.zip

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • This didn't help me unfortunately. This is the basic logic behind me game, but something is wrong. Again, I'm having trouble with the player health, and it will not deduct 1 health from game.PlayerHealth beyond the first astroid hit.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Can you upload your project file as a .zip file to Dropbox or another file-sharing site and then either post the download link here or send it to me in a private message? There may be some obvious reason your coding isn't working.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • Tatiang, thank you for your help thus far.

    Before I share my project with you, I will perform further testing to find this problem myself. So far I have found that if I use the term "if asteroidSmall overlaps/collides with actor of type Player, then deduct one health". This does not work, and the health is not deducted. However, if I modify that last line of logic to be "if asteroidSmall overlaps/collides with actor with tag Player, then deduct 1 health". This works! When the player collides with the asteroid, he will lose 1 health EVERY TIME he hits an asteroid. I have no Idea why this works versus the other method, which calls the actor specifically, not the whole group of "player" actors.

    I cannot use this method because I have other actors in that group that I do not want this rule to apply to (such as bullets). I will probably just proceed in separating the groups. However this will double the amount of rules needed to make asteroids explode on impact with both bullets and the player...

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Well, you could create a new tag and just put the Player actor in it but that all seems convoluted when really you should just be using When actor collides with actor of type [Player]. Is it possible that you have more than one actor called "Player" or "player"?

    Are you using Windows Creator or Mac Creator? The reason I ask is that you wrote "if" instead of "when" and that's one difference between the platforms.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • I have both. I'm currently using the windows creator, but I have opened my project on the mac creator and the problem is still there...

    By the way, I tried separating the player actor from the grouped actors and the result is that the health does not get reduced by one. I tried calling the actor both through its tag and actor type, and neither works...

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Sorry you're having so much trouble. Without seeing your rules or your project file, there's really no way I can help you further.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    When I preview the file and turn on the Collide with actor of tag [Asteroids], it only counts the first collision. I noticed that you're manually setting and changing actor tags to during gameplay. I don't recommend doing that. If you need to prevent an actor from being detected, try using a When self.color.alpha=0 rule condition. When I removed all of the tag behaviors and conditions, it seemed to function better.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • t.henstrand@gmail.comt.henstrand@gmail.com Member Posts: 14
    edited March 2014

    okay, but can the player hit an asteroid that is invisible? A problem with this is that the player can shoot an asteroid, making it's alpha 0, but then the invisible asteroid can hit the player, making the player lose life. To the player of the game it looks like he/she just lost life without hitting anything.

    EDIT: Also, I added in the lines to initially change actor tags as a potential fix to the problem. Those did not exist before.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    You're right... if the alpha is 0 the player can still detect a collision. I think when a bullet hits an asteroid, you should spawn an actor to spawn the explosion particles and destroy the asteroid actor(s) immediately after. That way you avoid this problem.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • But then the spawned actor will have a different trajectory than the asteroid because the asteroids each have a random trajectory. Do me a favor and restore everything to how it was and include the reduction of health into the "Gets Hit" rule on the asteroid itself. This will work, the player will lose 1 health every time he hits an asteroid, except the player will also lose a health when he shoots an asteroid, which is not wanted... but the collision works.... It's very odd that it would work in this rule and not another. To elaborate on this, I have tried duplicating the rule and separating the bullet and player actors out of the same tag group... this didn't work however.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    There's a way to pass trajectories from one actor to another but that's getting pretty complicated.

    The bottom line here is that you should be able to do this with tags and by having the collision rule in the player/ship actor only. If that's not working, try making a new blank file and just getting that aspect to work. Sometimes for whatever reason you have to backtrack a bit and get the basics working and then add in the rest.

    I updated the demo to use tags. Press the space key to shoot a bullet. Bullets change the alpha on the asteroids as well as their tags so that they don't decrease the ship's health. Maybe the problem was using "null" for the tag instead of just a blank string?

    https://www.dropbox.com/s/e08uitbgkz9cicw/asteroid collision v2.zip

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • So I took your advice and created a particles actor that spawns upon the asteroids being shot or hit by the player. It doesn't look as bad as I thought it would and everything seems to work just fine. However, I had to stop using tags to trigger things... As I went through all of the programming it became clear that none of the tags were registering. I am now calling the actors by "actor of type" and not with tags... This seems like a huge bug with Gamesalad. Maybe I'm wrong though.

    As I was making this game, the tags seemed to be working until the game reached a certain level of complexity... I have no idea though. This should definitely be looked at by the Gamesalad developers though.

  • meedoingmeedoing Member, PRO Posts: 18

    The actions you need must be inserted in the original prototype not the copy.

Sign In or Register to comment.