Draggable Objects going through walls

Hi,

Very new to GS so please bear with me!

I am creating a draggable puzzle game (photo attached, this is a prototype!). The problem I am having is that when you drag an object it doesn't obey the collide behaviour with the wall around the edge (in white currently). All the objects (black and light blue) need to be draggable. When they are moved in a specific sequence the blue object can slide out of the exit area.

I have googled this problem but no one seems to have solved it before! I have the desktop version and online version but I am better versed and practiced with the online version.

Any ideas or advice much appreciated.

Thanks

G

Comments

  • ucjugh0ucjugh0 Member, PRO Posts: 8

    I should mention each object only move in their length ways direction (left and right on x axis or up and down on y axis) on one axis.

  • ArmellineArmelline Member, PRO Posts: 5,363

    What logic are you using for the dragging?

  • ucjugh0ucjugh0 Member, PRO Posts: 8

    @Armelline said:
    What logic are you using for the dragging?

    At the moment this....

    I appreciate this is quite amateur at the minute but just starting out! Turns out what I thought was simple is a little more complicated! Logic for the collision is just as you would expect for a normal wall - but in this case it doesn't work.

  • ucjugh0ucjugh0 Member, PRO Posts: 8

    This logic is for the first from the left vertical black block. The drag works just how I want it to but the issue is it goes through the wall in either direction. I only want it to move on one axis.

    Thanks @Armelline for your quick response.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    I wouldn't say this is my area of expertise with GameSalad but one idea that comes to mind is keeping track of boundary areas (e.g. x and y positions in a table) for each block/wall and only allowing the constrained dragged actor to drag as far as the edges of that area. Don't know if that makes sense!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ucjugh0ucjugh0 Member, PRO Posts: 8

    @tatiang that sounds like it would make sense! Do you mind elaborating a little on where and how I might go about achieving that?

    Thanks for the response!

  • ArmellineArmelline Member, PRO Posts: 5,363
    edited February 2019

    Exactly what I'd suggest @tatiang.

    Something like

    Constrain self.Position.X to min((768-self.size.width/2),max((0+self.size.width/2),mouse.position.x))

    The 768 and 0 are the right and leftmost points the edge of the actor should hit.

  • ucjugh0ucjugh0 Member, PRO Posts: 8

    @tatiang and @Armelline thank you both for your help. I will give this a go and let you know if it works.

  • ucjugh0ucjugh0 Member, PRO Posts: 8

    @Armelline I think this is a real beginner question but how do you enter:

    Constrain self.Position.X to min((768-self.size.width/2),max((0+self.size.width/2),mouse.position.x))

    I keep trying it and it returns an error and won't let me update:

  • Two.ETwo.E Member Posts: 599

    If your wanting to save a lot of time. @UtopianGames has a great Unblock Me template on GShelper.com. I can't remember the name, but its something Choc-o-Block

    I know it costs money - but it shows you how to make it which is nice.
    Being able to drag an actor is only half the problem.

    The next problem you are going to face is that the collision you want is going to push the actors out of place. Even if you put a constraint on its X or Y position, it is going to be very inconsistent. (I did testing when I made a clone).

    The best approach is to have two instances of the same actor. One that is moveable, and one that is Solid. The moveable one will collide with the Solid, since the Solid don't move. That means you would need to either spawn / destroy actors when needed.

    I'm not sure if I can go too much into detail since I have worked on the template many times. Hoping Darren might allow me / him to share some insight.

    Best,
    Two.E

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @ucjugh0 said:
    Constrain self.Position.X to min((768-self.size.width/2),max((0+self.size.width/2),mouse.position.x))

    I keep trying it and it returns an error and won't let me update:

    That expression is correct. I haven't used the online version of Creator in about a year (it just took me nearly 30 seconds to figure out how to add a new actor!) but I entered that expression and even tried to create it anew using the auto-complete entries for min and max but it kept giving me the same error you got.

    Not sure what to make of that...

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ArmellineArmelline Member, PRO Posts: 5,363
    edited February 2019

    I just guessed the mouse.position.x part, I doubt it's actually that. I recommend repalcing that and the self.size.widths with attributes you pick using the attribute picker. I don't think you can just paste those parts in on the online creator (you can't on the desktop one).

    Two.E is right though, you're going to run into other problems. I've not tried this type of game before but I'll have a go and see if I can throw together a quick demo.

  • ArmellineArmelline Member, PRO Posts: 5,363

    Here's a quick demo. Very rough and untested, and you have to be more precise with the inital block placements than I've been, but should get you started.

  • Twayne2Twayne2 Member Posts: 458
    edited February 2019

    Add two conditions, besides touch is pressed, one saying if x position is less than or equal to the right wall minus half its width, and the other saying if x position is greater than or equal to the left wall plus half its width. Then move the block along the x axis. :)

  • Two.ETwo.E Member Posts: 599

    Nice demo. @Armelline

    A great way to improve upon it is making the moving actors shrink in width / height by a few pixels to avoid any collision problems.

    I am sure adding snap to grid should be easier enough for @ucjugh0 given how well you know your GS logic!

    Very cool to see.

  • ArmellineArmelline Member, PRO Posts: 5,363

    @Two.E said:
    A great way to improve upon it is making the moving actors shrink in width / height by a few pixels to avoid any collision problems.

    That's a great idea, though if I hadn't been so slap-dash in laying the actors out there should be no collision problems. But a small shrink would allow that sloppiness and would be a nice little indicator that the block was "selected."

    I'd probably not add snap to grid to this kind of game, but it definitely wouldn't be too difficult to add. Though if I was making it with snap to grid, I'd have that drive the whole thing, using a totally different method. No need for spawning/destroying actors if you can cleanly track all their positions.

  • ucjugh0ucjugh0 Member, PRO Posts: 8

    @Armelline this is very cool - and I am really grateful for your help! Thanks again, everyone!

  • Two.ETwo.E Member Posts: 599

    Sorry, I meant the Non Movable actors. This way they are always positioned correctly and easier to move around. I believe I added it to another developers Unblock game and it made such a difference in quality. You still had the freedom of moving each block around, but as soon as you released touch, it would snap into place so any other blocks could easily move. therefore focusing on the actual puzzle and not on touch accuracy.

    Just an Idea. I am just glad someone released an unblock template for free!!

Sign In or Register to comment.