Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tunneling issue #7

Open
Charathan opened this issue Mar 20, 2018 · 1 comment
Open

Tunneling issue #7

Charathan opened this issue Mar 20, 2018 · 1 comment

Comments

@Charathan
Copy link

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

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:

            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.

@Donaut
Copy link

Donaut commented Sep 25, 2020

I think the problem is with the last part.
image

480 is a too accurate value. Maybe try with some bigger value? Like 600

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

No branches or pull requests

2 participants