Get Object on Collision [SOLVED]

Hi! I think the solution would be to change from string to position [.X() | .Y()] in the receive event, instead of the sending event.

If you change the variables (X and Y variables) in the send event, it’ll send the coordinates for that object in the scene. However, if you change them in the receive event, the variables’ value will be the X and Y positions of the object in the scene of the client.

I thought that this could be helpful, though I don’t really know how to do it.

Best regards,
X

Hi! I don’t want to be annoying, but if you could just tell me something, like you are working on a project of your own, helping somebody else, taking a break, on vacation, working on my example, anything. Just so I know what’s going on, it’s weird not having any news at all.

Hope everything’s well,

X

Yeah, I’m not the best at keeping people posted to what I’m doing. I was a tad pre-occupied with 2 sick kids while working from home and trying to review as many GDevelop Game Jam games as possible. But that’s all done and dusted. Here’s what I’ve come up with :

The objects that you’ve named P1…P76 I’ve made into one object, and called it Spot with a instance variable (number) called Id.

I’ve then used the following events to position the spots. It sets them one way for the client1, and rotated 180 degrees for client 2 :


I added all the playing pieces into an object group, which I called PlayingPieces.

I also added a Tween behaviour to all the playing piece objects (just for the movement of a piece on the other player’s machine - it makes the animation easier to watch and more player friendly)

In the events that set the Dragged variable of the playing piece to true, you’ll need to add a subevent that gets the Id of the Spot object the playing piece is on and store it in S.StartSpotId. This is because we’re going to send just the start and end spots to the other player, and not the piece that’s getting moved.

I then modified the P2P calls as follows (note, I haven’t tested this, so you may need to do a little bug fixing, but you should get the gist of what it’s trying to do). These events should work for all your playing pieces, so there is no need to create specific events for each playing piece :


Try this out, and let me know how it goes.

1 Like

Hi! Thanks for the reply. I’m working on the example and the Spot part is working flawlessly. It looks just like before, but I deleted the P76 and below. I’ll continue working on the Dragged part.

Best regards,
X

Hi! So I tried the piece part, and it’s not working. However, I expected that (not because of the event themselves, but because I have a few adjustments I need to do, thanks to the different scenes and settings), and I’m adjusting now.

Now, I have a doubt; In the second picture, first event, on the line that triggers the event, I can’t put “S” in extra data, I have to put VariableString(S). Is that the same or is there something I don’t know?

X

Still, with that doubt, the code isn’t working, so I’m going to send pictures, only of the piece part, the Spot part works perfectly.

A few things:

  • PlayingPieces group is called Ps, with only the pieces, Black and White.
  • Spot is named P

I’ll try to debug it more and keep you posted.

I just had an idea. Maybe I need to delete the movement events;

These events are in every piece, in both IsClient events. I tried removing the movement event (Grid action event), but it just wouldn’t move (Shockers). I don’t know if the tween is supposed to move the other client’s piece to the piece moved (like before) or to move both at once. It’s my first time using tween behaviour. I only did this in the white Star, if the IsClient is false. But I thought maybe the events where blocking the movement or something like that. Like I said, i never before used the Tween behaviour.
Maybe the images are helpful.

Best regards,
X

I had some typos in my test project (for one, Move.Variable(StartSpotId) should have been Variable(Move.StartSpotId)). I’ve had some time to look at it, and fixed them. It’s not the same level as checking for valid moves as you have, and I use the drag behaviour to move the pieces around. But hopefully it’ll help you.

Here’s is a link to the PoC project I rustled up. I don’t know how long I’ll leave the link up for (probably a few months), but I’ll include screen shots at the end in case anyone reads this later on and the link is dead.

Here is what my PoC looks like (star is the dark grey object) :

P2P_Move_Board


Here are the event groups rolled up :


The Setup just contains the setup in the screen snip of my earlier post.

The other two event groups are as follows (remember I’m using the drag behaviour which I’ve attached to the Star object) :

and

I have found the occasional glitch where a move is not received by the client. I’m not sure what that one is about, probably the default P2P server that’s failing.

Hi! I just got to testing the game and that’s exactly what I’m shooting for! One thing, though. In my game, I use the Dragged variable to imitate the Dragged behaviour. Can I do the same thing in your example?

Edit: I tried to research this but got no straight anwser; what is to “Parse Json string”?

Edit 2: Here are the code’s images;

X

Certainly. You do that whatever you like with the PoC project.

However, I’d suggest using the drag behaviour, because it’s something that works and will reduce the events you need. I’d also suggest you don’t determine a playing piece’s move moves with hard coded positions in events.

Instead, store the positions (which will be relative rather than absolute) in an instance array on each playing piece object, and use this data to position the possible move targets. This way you can modify or add new pieces without having to change the events. And it will significantly reduce the number of events - you’ll only need one set of events for all playing pieces.

I can update the PoC project to show what I mean, if that would help. Let me know.

Too slow with your response :smiley: I’ve updated the project files in the previous link. Here’s what it looks like now :

P2P_Move_Board


Have you checked out this wiki page?

But I realised after I uploaded the PoC project that the JSON part wasn’t needed. My last screen shot shows how to do it without JSON (and it’s been taken out of the updated PoC project).


In your first screen shot, you want to use Left mouse button was pressed.

In your second screen shot, first event, remove the The cursor/touch is on Ps condition. The cursor will be on Ps because it’s being dragged. If you wait until it’s no longer over Ps, then the Left button released condition won’t be true any longer, so that event will never fire.

2 Likes

Hi!

Weird how I didn’t see that while searching for the meaning. I’ll check it out.

Thanks! I’ll try it out and see if I ran into any problems.