You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi John! I'm resuming work on my platformer and am trying to figure out the best way of determining if a user is in contact with a block/actor in a group.
My use-case is I have my player who will walk off the edge of an obstacle. When he walks off the edge I want to get a notification that he's no longer in contact with the ground so that I can apply gravity.
See GIF for my current behavior:
I've accomplished this by adding the following methods to Actor:
publicfunc isInContact(withBlockGroup group:Group)->Bool{
for block in blocksInContact {
if block.group == group {return true
}}return false
}publicfunc isInContact(withActorGroup group:Group)->Bool{
for actor in actorsInContact {
if actor.group == group {return true
}}return false
}
I have a plugin that watches for rectChanges and flips a flag which changes gravity behavior:
actor.events.rectChanged.addObserver(self){(scene, player, stuff)in
if !player.isInContact(withBlockGroup:self.floorGroup){
if self.isGrounded {self.isGrounded = false
}}}
Is there a better/more efficient way of doing this? If not I'd be happy to open a PR with the change.
The text was updated successfully, but these errors were encountered:
The way i've done this kind of collisiondetection is with a "2d"array, int[][]. It is done in c++, but i think it's somehow the same.
The size of 1 index in the array is 32*32 pixels, so the array coords for (24, 21) = [0][0] and (43,24) = [0][1]
I check if the array position below me has an value > 0 (a tile ID), if so, collision!
collidableArray[(int)(player.GetPosY()/ 32) + 1] [(int)player.GetPostX()/ 32] > 0, accessing array index O(1), so it's a really fast checkup
Hi John! I'm resuming work on my platformer and am trying to figure out the best way of determining if a user is in contact with a block/actor in a group.
My use-case is I have my player who will walk off the edge of an obstacle. When he walks off the edge I want to get a notification that he's no longer in contact with the ground so that I can apply gravity.
See GIF for my current behavior:
I've accomplished this by adding the following methods to Actor:
I have a plugin that watches for rectChanges and flips a flag which changes gravity behavior:
Is there a better/more efficient way of doing this? If not I'd be happy to open a PR with the change.
The text was updated successfully, but these errors were encountered: