Stop Drag Through Walls

GendudeGendude Member Posts: 15
edited November -1 in Working with GS (Mac)
I am working on a game that require objects to be drag around and I was able to setup the drag & drop part of it, but I can't figure out how to prevent the objects to drag through the walls and floor. I have a collide behavior on the objects, but only works when the objects are not been drag.

Thanks in advance to the person that help
Gendude

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi, yes, as you've found out, there are problems with collision detection with dragged actors. I made a workaround a while back, which works best when the drag Rules are amended so that the dragged actor drags from the touch point, not its centre jumping to touch first. There's a few examples of that around if you need that, (can't remember off the top of my head to let you know) - one by FireMapleGames I seem to remember, and one called (possibly) Drag and Spawn.

    Anyhow, the following still works with the standard dragging Rules (created by Tshirtbooth, I believe), just not quite as well; the following will be for the left wall. Duplicate for right, top and bottom, changing the Move To accordingly, eg. for top, figures will be Move To position self.Position.X, self.Position.Y-20; etc.

    Rule: When Actor overlaps or collides with Actor of type LeftWall
    Change attribute self.DragAndDrop to false
    Collide Bounce when colliding with actor of type LeftWall
    Move To self.position.X+20, self.position.Y speed 300

    Rule: when all conditions are valid
    When touch is pressed
    when touch is inside
    Change attribute self.DragAndDrop to true
    otherwise
    Change attribute self.DragAndDrop to false

    ---then the following amended so that the item dragged doesn't jump to the touch point but is still draggable---

    Rule: When attribute self.DragAndDrop is true
    Constrain Attribute self.Position.X to game.Touch. touch 1.Position.X
    Constrain Attribute self.Position.Y to game.Touch. touch 1.Position.Y

    Hope this sorts this for you.
Sign In or Register to comment.