How can I have an attribute trigger when an actor collides with only the top part of another actor?
jckmcgraw
Member Posts: 647
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.
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
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.
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
-
domenius Posts: 108Hmm, 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_c ImagineLabs.rocks Posts: 5,772Hi 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
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
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
@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
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?
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
I'll try that when I get home from school today.
Jack
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
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