bump
bump copied to clipboard
rectangleCollision (and possibly others) seem to break with constant acceleration mechanic
I have a platfomer with a constant acceleration built in to simulate gravity:
let playerGravity = 0.2; playerSprite.vy += playerGravity;
collision detection for playerSprite and array of sprites that are allowed to collide with the playerSprite:
if( b.hitTestRectangle(playerSprite, collSprites[i])){ b.rectangleCollision(playerSprite, collSprites[i], false);
where:
b = new Bump(PIXI);
on "impact" where playerSprite lands on top of a tile with which it can collide first aligns the playerSprite to the tile, then after ~1 second @ 60fps, the playerSprite disappears. Movement is also hindered after collision to whole tiles before playerSprite disappears.
Update: The disappearing issue appears to be a related to collisions with multiple rectangles at the same time.
For testing, I made only a single block collideable, and the r1 sprite no longer disappears.
However, even with a single tile only colliding, the r1 sprite is moved left until they are dumped off the tile.
I'm new to Hexi, so this may be a dumb question - but why are you calling hitTestRectangle first? Surely this will only prevent things overlapping if they are already colliding. What if the player is not colliding with the tiles already, and moves fast enough to pass through?
@jbockmon Have to seen the platformer example here?
https://github.com/kittykatattack/hexi/blob/master/examples/src/platforms.js
@JamesCraster: you're correct, in this case there's no need to call hitTestRectangle
- a simple rectangleCollision
will do.
@JamesCraster the algorithms for detecting collisions in hitTestRectangle and rectangleCollision are different. Furthermore. hitTestRectangle does not alter sprite vx or vy directly, nor does it alter its x or y coords. rectangleCollision, on the other hand, checks for collisions as well as handles sprite movement/correction to prevent collision.
When I relied on rectangleCollision alone, the algorithm it employs returns left/right collisions as well as bottom/top collisions when the lhs sprite spans two or more blocks/sprites. Because rectangleCollision directly modifies the vx and vy values, these left/right collisions would stop my lhs sprite from being able to move. I use hitTestRectangle to filter the unncessary left/right collisions out to prevent it from setting lhs.vx to 0.
@kittykatattack I have not. I will have to check it out. Thanks!