How can I have an attribute trigger when an actor collides with only the top part of another actor?

jckmcgrawjckmcgraw Member Posts: 647
edited June 2012 in Working with GS (Mac)
Hello Everybody,

I have been trying to figure this out for quite a while, but to no avail. I have a picture below of the main code (the expression editors opened correspond to the top part), which doesn't seem to be working too well...

Here is some more background on the issue... I have an integer jump attribute that changes between 1 & 0 (I suppose it could be a boolean). It limits the amount of times you can jump to 1. Additionally, in the main character, I have 2 game attributes (game.playerX, and game.playerY) constrained to its self.pos'

Rule: when up arrow is pressed & game.jump = 1, change the velocity & change att game.jump to 0.

Now in the platform (that can be floating in the air), the code is in the screenshot below. It is only partially working. :( It will set game.jump to 1, but it will still set game.jump to 1 even if you overlap with the side of the platform.

image

Please let me know if this needs to be made more clearly for you to understand it. I appreciate anybody's help! :)

Thanks,
Jack McGraw

Best Answers

  • domeniusdomenius Posts: 108
    edited June 2012 Accepted Answer
    Hmm, now that I look at this again I'm not sure what the heck I was thinking before, don't do that ;). I think the issue is stemming from not taking the players height into account as well as the height of the platform, so you have pretty much the right idea except you should add to the equation half the players height and width and then minus 1 to keep the top pixel active. Essentially those checks are always going to pass since playerY is not = to its bottom pixel, but rather to its midpoint.

    try this: if PlayerY>self.pos.y+(self.size.height/2)+(PlayerHeight/2)-1 <--could just shove a number in for PlayerHeight that is half the players height rather than doing the last bit of that calculation.

    TBH, you could probably just limit the X instead and leave all of Y active. For that you'd want to do: if PlayerX>self.pos.x+(self.size.width/2)+(PlayerWidth/2)+1 and if PlayerX<self.pos.x+(self.size.width/2)+(PlayerWidth/2)-1
  • jamie_cjamie_c ImagineLabs.rocks Posts: 5,772
    edited June 2012 Accepted Answer
    Hi jckmcgraw,

    What I was getting at with the wall platform is that you could put it at the edges of your floor platform and on the bottom of it if you needed too so the jump would not trigger there. It would be a bit more work when building the game but might be a workable solution.

    Hope you get it worked out.

    Jamie

Answers

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    i'm working on a platform game as well and had to make two different actors, one for a floor and one for the walls. The floors count my jumps similar to what you show above but the walls don't. It's a bit of a pain but seemed to be the best way I could get it to work correctly.

    On a separate note, you can compare your players Y postion to another actors Y position to see if one is on top of the other but that didn't work well for this issue for me since you'd have to kepp track of all of your platforms Y positions.

    I hope this helps.

    Jamie
  • domeniusdomenius Member Posts: 108
    edited June 2012
    You could try differently limiting player.y or player.x, something like: if player.y>platform.y+(desired offset), or limit the x to player.x>platform.y+(desired offset right) and player.x<platform.y-(desired offset left). Or both.
  • jckmcgrawjckmcgraw Member Posts: 647
    @jamie_c, I'm not concerned about the walls (I've in fact already made actor with different rules), but I can't have the jump be triggered when it touches the side or bottom of a platform...

    @domenius, Sorry, but how would limiting the player's x and y help with the jump? I tried using it a bit in the image I put up, but it didn't work quite as I had planned.

    I really appreciate your help!
    Jack McGraw
  • domeniusdomenius Member Posts: 108
    edited June 2012
    Limit to only top of the platform like this:

    PlayerY>self.position.y+(self.size.y/2-1)+(self.size.height/2)

    Now only the top pixel of the actor should trigger. You could still "clip" the edge of the top pixel on the side with this, so you could also try using the same idea on the sides.
    PlayerX>self.pos.x-(self.size.x/2+1)+(self.size.width/2)

    Make sense?
  • jckmcgrawjckmcgraw Member Posts: 647
    edited June 2012
    @domenius

    Thanks again for all of your help...

    So taking away the one pixel will prevent the actor trigger when hitting the sides? *-:) I'm going to try this out!

    EDIT: There is no such thing as "self.size.x (or y)" :/

    Jack
  • jckmcgrawjckmcgraw Member Posts: 647
    @Domenius

    I'll try that when I get home from school today.

    Jack
  • jckmcgrawjckmcgraw Member Posts: 647
    edited June 2012
    @jamie_c

    That is a possible solution, but I'm going to have way too many platforms for that to be a reasonable idea. There would simply be too many actors to load.

    Thanks for the ideas,
    Jack McGraw
  • jckmcgrawjckmcgraw Member Posts: 647
    Hi @domenius and @jamie_c,

    Thank you some much for all of your help... I found the solution, and feel like a dummy. 8-X Everything that I originally had posted in the picture worked except the game.overlap-platform attribute that wasn't even directly related to the problem. It was not triggering correctly.

    Thanks again,
    Jack McGraw
Sign In or Register to comment.