dotnet-ad / dotnet-ad/Humper

Tunneling issue

Open
#7 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
125
Forks
18
PR merge metrics
No merged PRs in 30d

Description

Hi,
I was working on a game in Love2D and decide to port it to Monogame. Finding Humper helped me a lot since I was using Bump in Love2D but I did run into a issue I didn't have in bump:

![test](https://user-images.githubusercontent.com/8489240/37656874-9817aa50-2c49-11e8-9be6-f37208165d04.gif)

I start off with a world with a width of 480 and height of 280 and cell size of 64 and 56 spheres (a 16 by 16 AABB) falling, the green number counts the spheres in the world, and make them fall, most of them bounce back using the default collision response but some of them pass through the floor. Am I doing something wrong or is this a bug?

The sphere have the following collision response:
```C#
float nx = 0, ny = 0;
float dt = (float)gametime.ElapsedGameTime.TotalSeconds;
_vy = Math.Max(_vy + (_gravity * dt), _maxHeight);

nx = Position.X + (_vx * dt);
ny = Position.Y + (_vy * dt);

var move = _box.Move(nx, ny, (collision) =>
{
if (collision.Other.HasTag(EntityType.Wall))
{
return CollisionResponses.Bounce;
}
return CollisionResponses.Cross;
});


foreach (IHit hit in move.Hits)
{
if (hit.Box.HasTag(EntityType.Wall))
{
if ((hit.Normal.X < 0 && _vx > 0) || (hit.Normal.X > 0 && _vx < 0))
{
_vx = _vx * -1;
}
if ((hit.Normal.Y < 0 && _vy > 0) || (hit.Normal.Y > 0 && _vy < 0))
{
_vy = _vy * -1;
}
}
}

Position = new Vector2(_box.X, _box.Y);

if (_box.Y > 480) // if they tunnel through the floor...
{
_entities.Remove(this);
}
```

The walls don't have a response since they are static.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.