Collision mask moves with touch event, not player sprite

I have set up a quite simple game, where player can be moved from left to right with touch to avoid obstacles coming from above (Behaviour “draggable” on the player sprite). To create some sort of bounding box, I used the extension “stay on Screen” with margins on all 4 sides. The collision with obstacles works great as long as the finger / mouse is on the player.

Problem occurs when I drag the Player outside his bounding box. It seems as if the sprite gets stuck at the border as expected, but the collision box stays on the pointer, not on my player. So as long as I do not release the mouse or lift the finger no collision between player and obstacle is triggered.

Is there any way to keep up a bounding box where the player cannot be dragged outside and keep the collision on the sprite anyway?

You should be dragging the collision box (assuming you have a separate sprite and collision box objects). And then set the player’s position to that of the collision box.

The Idea sounds brilliant, but how do I drag a collision box? There is no separate object “collision box”. Just a sprite with a box attached to it.
What I tried was making an Invisible Object “PlayerDrag” that I placed above the Player. Then I unchecked the player behaviour “draggable”, made the new object draggable and made the player follow it.

Screenshot 2021-10-13 162158

But the effect is the same. The player stays inside it’s margin but his collision box follows the “PlayerDrag” object wherever it may go.

Update:

It works as expected if I let the player follow the dragging sprite with forces:

Screenshot 2021-10-13 171746

But on the downside:

  1. the moment the player sprite reaches the drag sprite and it is still pressed he starts to “wobble around”.
  2. the movement of the player is not very accurate this way and can get quite frustrating.

Update 2 (I’m sorry):

the player sprite does follow the mouse as long as it is clicked, not the dragging sprite itself. I put my dragging sprite into the same boundaries my player has, and if I try and drag it out of it’s boundaries the player rotates always toward the mouse-cursor. So maybe this is some kind of bug of the draggable behaviour?

I think we may be talking different things here. I assumed when you mentioned about dragging the player outside their boundary, you were using 2 objects - one for the image and one for the collision.


Yes, applying a force on an object to reach a position will create that wobble effect. This link explains why, and a potential fix.


What do you mean with boundaries?

And could you provide a screenshot of your events that move the sprite? Then we know what we’re working with.

You’re right. I should explain better. My Player is a normal sprite that can only be dragged in a small part of the game. To achieve that I used the “stay on screen” Function.

(the enormous top margin is due to the fact, that the game is supposed to run on a full HD touch in portrait mode)

In my Game I now have an obstacle I try to avoid. Look at the mousepointer dragging my player:
ezgif-2-2a5066690ea8
And if I drag with the mouse out of the boundaries:

2

For me it seems as if only the sprite is held by the margins. The collision Map stays at the mose/touch position.

Thanks for that, I get what you mean with boundaries :smiley:. That sliipin though an object is an interesting behaviour - I have experienced something very similar myself a couple of days ago, but with arrow key movements, where 2 walls met and the player managed to pass through, even though it shouldn’t have been able to.

I don’t think the collision box is moving from the sprite. Since we’ve both experienced it using different mechanisms, I’m beginning to suspect there may be a bug.


But to confirm the collision box, could you turn on debugging in the event action like below, and check the object’s collision box when you drag the player? You can select it as an action :

image


So it’s like this :

That’s a cool feature!
But you are right. According to the debugger the collision box stays right where it is supposed to be. But the collision is only triggered when the pressed mouse/touch is over the object. As far as I can tell it behaves like it is dragged (the closer I have the pointer to my player, the more likely a collision takes place) with the mouse.

But I do not understand enough of Gedevlop to look for this - only started using it a couple of days ago.

Update:
If i move my Pointer to the very top of the screen (where the obstacles first appear) they vanish as if collided with the player sprite who is at the very bottom at this moment. So I can confirm, the collision is triggered always around the pointer, not the sprite.

Could you provide a screen shot of the events around the collision checks?

I’m not sure what you mean, so here is the part from my script - nothing spectacular here:

What I did now was building an Obstacle along the left side of the screen (that the player sprite is not supposed to reach) and freeze the game the moment it is in collision with player. from this freeze I can go to debugger and look at my players variables, and they state (as far as I understand them) that there is no collision between player and my new box:
That’s the exact frame of the freeze
Screenshot 2021-10-15 062619

The right corner of the white line where the collision box ends is exactly at x=930px
And the debugger says:
{
“x”: 730,
“y”: 1510.815074496056,
[…]
“vertices”: [
[
730,
1510.815074496056
],
[
930,
1510.815074496056
],
[
930,
1710.815074496056
],
[
730,
1710.815074496056
]
],
“edges”: [
[
200,
0
],
[
0,
200
],
[
-200,
0
],
[
0,
-200
]
],
“center”: [
942.1735319894829,
1610.815074496056
]
}
],
“hitBoxesDirty”: false,
“aabb”: {
“min”: [
730,
1510.815074496056
],
“max”: [
930,
1710.815074496056
]
},
[…]
“owner”: “[Removed from the debugger]”,
“_activated”: true,
“name”: “Draggable”,
“type”: “DraggableBehavior::Draggable”,
“_nameId”: 2,
“_draggedByDraggableManager”: {
“_draggingSomething”: true,
“_draggableBehavior”: “[Circular ~.payload._sceneStack._stack.0._instances.items.Player.0._behaviors.0]”,
“_xOffset”: 96.79228746713409,
“_yOffset”: 82.73444347063969,
“leftPressedLastFrame”: true
}
},
{
“owner”: “[Removed from the debugger]”,
“_activated”: true,
“name”: “StayOnScreen”,
“type”: “StayOnScreen::StayOnScreen”,
“_nameId”: 3,
“_runtimeScene”: “[Removed from the debugger]”,
“_onceTriggers”: {
“_onceTriggers”: {},
“_lastFrameOnceTrigger”: {}
},
“_behaviorData”: {
“MarginTop”: 1500,
“MarginBottom”: 200,
“MarginLeft”: 190,
“MarginRight”: 350
}
}
],
“name”: “Player”,
“type”: “Sprite”,
“_nameId”: 1,
“id”: 1,
“_runtimeScene”: “[Removed from the debugger]”,
“hitBoxes”: [
{
“vertices”: [
[
730,
1510.815074496056
],
[
930,
1510.815074496056
],
[
930,
1710.815074496056
],
[
730,
1710.815074496056
]
],
“edges”: [
[
200,
0
],
[
0,
200
],
[
-200,
0
],
[
0,
-200
]
],
“center”: [
942.1735319894829,
1610.815074496056
]
}
],
[…]

I removed a lot of Data - still to much left, but there are the X-coordinates for my player readable. Everything seems fine, except the coordinates for “center” which say x=942. That is way left of what the image says. So for me it looks as if the center gets dragged onwards with the mouse.

Sorry for the long post…

No worries about the post. It really helped to work out what could be going on.

And I think I got it worked out - are you checking for collision before you correct the player’s position?

I can replicate your issue if I do this :


But it works perfectly if I change it to this :

1 Like

You’re a genius. That worked.
Even with the behaviour “draggable” and margins, you need to reset the players position in the very beginning if he is dragged past this margins.
Now it is possible to drag him around and the collision only happens when the sprite touches an obstacle, not the mousepointer.

Thanks a lot.