YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
24 stars 8 forks source link

Add option to ignore self when using move_and_collide #2887

Open maunovaha opened 1 year ago

maunovaha commented 1 year ago

Is your feature request related to a problem?

I am atm. programming simple game server prototype for a RPG and I want to move players around the colliding objects using the move_and_collide function. I want players to collide with each other and tilemap objects, so I have decided to create an array of m_CollisionObjectTypes that can be used with move_and_collide function.

var layerBlockingId = layer_get_id("layer_Blocking");
var layerBlockingTilemapId = layer_tilemap_get_id(layerBlockingId);

m_CollisionObjectTypes = [layerBlockingTilemapId, obj_NetworkPlayer];

However, the problem is that the player seems to collide with itself and cannot move at all. Atm, I am not sure if this is intended behavior or not but it makes it very hard to use the function effectively. Below is a simplified version of the code I am using:

MovePlayer = function(_clientId, _x, _y)
{
    var player = GetPlayerState(_clientId).instanceId;
    var collisionObjectTypes = m_CollisionObjectTypes;

    with (player)
    {
        var xDistanceToMove = _x - x;
        var yDistanceToMove = _y - y;

        // Moves the player around colliding objects
        var collidingInstances = move_and_collide(xDistanceToMove, yDistanceToMove, collisionObjectTypes);

        // For some reason `collidingInstances` array is empty when colliding with itself(?)
        show_debug_message(collidingInstances);
    }
}

I have also tried to call the function using:

var collidingInstances = move_and_collide(xDistanceToMove, yDistanceToMove, obj_NetworkPlayer);

But the same problem persist as long as the player is trying to collide with other players. I am using the latest game maker version 2023.8.2.108 (ide) and 2023.8.2.152 (runtime)

Describe the solution you'd like

In this context, the player should not collide with itself or there should be possible to call the function with an additional parameter that can be used to ignore the player itself from the collision.

Describe alternatives you've considered

No response

Additional context

No response

KormexGit commented 1 year ago

IMO it would make sense for move_and_collide to automatically filter out the calling instance, just like functions such as place_meeting do. I can't think of any possible scenarios where you'd want an instance to move_and_collide with itself, since that just makes it not move. So I think this could be the default behavior, no option needed.

jackerley commented 11 months ago

Hi @maunovaha I've run some tests and from what I can see, move_and_collide already ignores self, I think that there must be some other problem with how you are calling move_and_collide - check the attached sample where all the moving objects are of type Object2 and the player object will collide correctly with the non-player controlled instances and ignore itself.

moveandcollideselftest.zip