Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Collision detected but touches not assigned #130

Closed
MathieuLoutre opened this issue Aug 23, 2016 · 8 comments
Closed

Collision detected but touches not assigned #130

MathieuLoutre opened this issue Aug 23, 2016 · 8 comments

Comments

@MathieuLoutre
Copy link
Contributor

Hi there,

I'm playing with collisions and I've made an NPC and a PC Actor with an arcadeBody2D components. They both move fine on the Tile Map but when I go to check collisions between the two actors I get strange results.

The collision is detected (.collides returns true and .detachFromBox is called) but all the touches are marked as false. I've looked at the code in .detachFromBox and it seems to go through the first if statement fine (detecting if it's on the Y or X axis) but then there's another if inside which checks body1.deltaX() / insideX > 0 (https://github.com/superpowers/superpowers-game/blob/master/plugins/default/arcadePhysics2D/components/index.ts#L40) and this one seems to be causing problems.

Because that statement is not true (deltaX is negative) it never gets in to assign the touches. If I remove that if condition, it seems to work fine. I can't quite understand what that condition is supposed to guard against but in any case, shouldn't there be an else to fill in the blanks? Having a collision but no touches is quite confusing.

Here's a demo of what's happening: https://gfycat.com/UnevenFamousKilldeer

The code looks like that (in the update call of the Dino):

if (Sup.ArcadePhysics2D.collides(this.actor.arcadeBody2D, this.playerBody)) {
       if (this.actor.arcadeBody2D.getTouches().left) {
         Sup.log("left")
       }
       if (this.actor.arcadeBody2D.getTouches().right) {
         Sup.log("right")
       }
       if (this.actor.arcadeBody2D.getTouches().top) {
         Sup.log("top")
       }
       if (this.actor.arcadeBody2D.getTouches().bottom) {
         Sup.log("bottom")
       }
}

As you can see in the video, none of this gets logged.
Additionally, I've put logs in the code of detachFromBox which you can see the video:

// At the top
console.log("X", body1.position.x, body2.position.x)
console.log("Y", body1.position.y, body2.position.y)
// After the first inside calculations
console.log("INSIDEX", insideX, "INSIDEY", insideY)
// After the first if (Y)
console.log("Y", body1.deltaY(), insideY, body1.deltaY() / insideY > 0)
// After the first else (X)
console.log("X", body1.deltaX(), insideX, body1.deltaX() / insideX > 0)

I hope I'm missing something silly but I've checked a few things (removing offsets/resizing the hit boxes) and nothing works. The only time it seems to work is when the PC doesn't move and the NPC collides with it.

@MathieuLoutre
Copy link
Contributor Author

@bilou84 Hey! Do you think you'd have the time to look at this anytime soon? I've hacked together something in my local version for now (removing the if) but I'm pretty sure I'm missing the point.

@bilou84
Copy link
Contributor

bilou84 commented Sep 3, 2016

Sorry it took so long to get back at you. Will have a look this weekend!

@bilou84
Copy link
Contributor

bilou84 commented Sep 3, 2016

Ok, so the check is basically to make sure your body is currently moving in the direction of the intersection. It prevents for instance a motionless body to get pushed by another because this is not supported at all.

You can easily give it a shot with this game https://github.com/superpowers-extra/octofoot-game.
If you remove the condition, the player 2 can push the player 1 around and the ball is able to push players as well.

But you are correct that we should still set the touches value correctly so I will fix that.

@bilou84 bilou84 closed this as completed in 6ece26b Sep 3, 2016
@bilou84
Copy link
Contributor

bilou84 commented Sep 3, 2016

Thanks for reporting the problem ;)

@MathieuLoutre
Copy link
Contributor Author

Great! I see it now. Thanks for fixing, I'll give that a go :)

@Elmapul
Copy link

Elmapul commented Sep 3, 2016

the bug is still here (version 2.0) , this fix will be avaliable on the next relase or it should already be working?

@bilou84
Copy link
Contributor

bilou84 commented Sep 3, 2016

It will be on the next release, probably by the end of the month

@Elmapul
Copy link

Elmapul commented Sep 3, 2016

thanks :D

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants