GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Hurt if actor is moving...

Alright, so, I have a rather simple task with many specifics I haven't been able to figure out.

I have the "player" or called the "heart" in this game. When the player overlaps/collides with an orange projectile and the player is NOT moving, the player's health is set down. That's it simply. I can manage the health.
However, what I can't find out is the recognition. I have walls alongside the area in which the player is. Again, as stated, I need to make the player be hurt when they collide with a projectile while NOT moving.
Pinpointed, the issue is that I do NOT want moving against the walls to count as moving. For instance, if the player is on the left wall and holding in the left arrow key (to move, but obviously cannot move left because there is a wall there), they should NOT get hurt.
Any help? Thanks for any responses in advance!

Comments

  • tatiangtatiang Posts: 11,734Member, Sous Chef, PRO, Senior Sous-Chef
    edited August 2018

    Create a boolean attribute called game.touchingWall. Then, in the player actor, have these rules:

    When actor collides with actor [wall]
         Change attribute game.touchingWall to true
    Otherwise
         Change attribute game.touchingWall to false

    When actor collides with projectile AND attribute game.touchingWall is false AND [moving is false]
         [reduce health]

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

  • Loganblahtimes2Loganblahtimes2 Posts: 2Member, BASIC

    Thank you for your response! Albeit that wasn't what I was going for.
    I was going for the actor can get hurt anywhere on the field so long as it is moving. However, if it is moving in the DIRECTION of the wall, for instance, a wall is to its left (direct left/touching) and the player IS being hit by the projectile, it will NOT hurt it.

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

    Fair enough... I was responding to this:

    if the player is on the left wall and holding in the left arrow key (to move, but obviously cannot move left because there is a wall there)

    Not sure how to achieve what you want but maybe my input will help you get there.

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

  • bob loblawbob loblaw Posts: 294Member, PRO

    maybe something that looks a little like this:

    create two actors the same height as the player actor and width of 2 called LeftSide and RightSide

    global variables of leftTouch (integer set to 0), rightTouch (integer set to 0), PlayerX (real), PlayerY (real), PlayerWidth (integer), PlayerHeight (integer)

    player actor variable hitActive (integer set to 1)

    change attribute PlayerWidth to the width of the player actor
    change attribute PlayerHeight to the height of the player actor

    constrain (within the player actor) playerX and PlayerY to the player.self x and y
    constrain leftTouch to the left side of the player (constrain leftTouch to game.PlayerX-[PlayerWidth/2]), and do the same for Touch right but + instead of -.

    within actor LeftSide create a rule that says if actor overlaps/touches actor walls, change attribute game.leftTouch to 1, otherwise change attribute game.leftTouch to 0. do the same for the actor RightSide but with rightTouch.

    within the player actor have rules if all are true:

    • if leftTouch = 1 and rightTouch = 0 and self.motion.linearvelocityX < 0 then self.hitActive=0
    • if rightTouch = 1 and leftTouch = 0 and self.motion.linearvelocityX > 0 then self.hitActive=0
    • if rightTouch = 0 and leftTouch = 0 a then self.hitActive=1

    then within the rule you have in the player actor that decides if whatever hits the player is hit, add a condition that says if self.hitActive = 1

    that's just off the top of my head. i hpoe it makes sense. might need a little tweaking and there's probably a better way to do it, but give it a go.

Sign In or Register to comment.