haxball / haxball-issues

115 stars 43 forks source link

Change Joints During the Game #2200

Open vitormarchini opened 6 days ago

vitormarchini commented 6 days ago

¹• I would like to know if it is possible to join, for example, disk 0 with disk 5 while the game is running.

²• Another thing. I know that it is not possible to join a disk to a player through HaxPuck. However, is it possible to do this through a script, since, as soon as the player enters the field, he becomes a disc? If it is possible, could you explain to me the correct method to do this?

³• Is it possible change cMask, cGroup and trait of discs while the game is running?

NOTE: I am a map creator, I understand the bare minimum of javascript, but to create BOTs, I only use ChatGPT, I'm sorry for my ignorance.

alpheratz0 commented 4 days ago

¹• I would like to know if it is possible to join, for example, disk 0 with disk 5 while the game is running.

Hi! You can't join them directly, but you can move discs. For example, you could move discs 6 and 7 (connected by a joint) to where discs 0 and 5 are, and then move 0 and 5 off the screen.

²• Another thing. I know that it is not possible to join a disk to a player through HaxPuck. However, is it possible to do this through a script, since, as soon as the player enters the field, he becomes a disc? If it is possible, could you explain to me the correct method to do this?

Currently, the API doesn’t support that. However, there are some tricks that can get you close to what you want, though they aren’t perfect. One approach is to wrap the player in a box made of joints. You could then programmatically move the box around the player (just once) as needed.

³• Is it possible change cMask, cGroup <...> of discs while the game is running

You can, see setDiscProperties, getDiscProperties, setPlayerDiscProperties and getPlayerDiscProperties.

You may also want to check the CollisionFlags page.

const { CollisionFlags } = room;
room.setDiscProperties(0 /* disc index, 0 = ball disc, 1 = 1st stadium disc, 2 = 2nd stadium disc... */, {
    cGroup: CollisionFlags.all, // in stadium files this is the same as ["all"]
    cMask: CollisionFlags.red | CollisionFlags.blue // in stadium files this is the same as ["red", "blue"]
})

... and trait of discs while the game is running?

No, once the stadium is parsed and loaded, traits are gone. Traits are only useful for map editors.

vitormarchini commented 23 hours ago

Thank you so much, @alpheratz0

About moving the discs around the player, I coincidentally did something similar a few years ago, but only for maps, I hadn't started using BOTs. However, through scripting, I'm facing another problem that you would probably understand and I would like you to help me, if possible, through Discord when you have time so I can show you in real time what happens.

About cGroup and cMask, I still haven't been able to fix them to change them during the game. I'm also having problems with bCoef, which, when I use a command to change the bCoef of a disc during the game, nothing happens.

Right now, the commands is working (wrongly) like that:

    case 'bCoef':
        if (!isNaN(value[0])) {
            room.setDiscProperties(index, { bCoef: value[0] });
            room.sendAnnouncement(`Disco ${index} coeficiente de quique alterado para ${value[0]}`, playerId);
        } else {
            room.sendAnnouncement("Valor de bCoef inválido!", playerId, 0xFF0000);
        }
        break;

    case 'cMask':
        room.setDiscProperties(index, { cMask: args.slice(2) }); // Máscara de colisão como string
        room.sendAnnouncement(`Disco ${index} máscara de colisão alterada`, playerId);
        break;

    case 'cGroup':
        room.setDiscProperties(index, { cGroup: args.slice(2) }); // Grupo de colisão como string
        room.sendAnnouncement(`Disco ${index} grupo de colisão alterado`, playerId);
        break;

Could you call me on Discord so we can briefly discuss these details?

My Discord: vitaohr.