Problem. need help of EXPERTS :D

giacomopoppigiacomopoppi Member, PRO Posts: 914
edited November -1 in Working with GS (Mac)
hi i have a big problem with one of my games.
i have 2 actors:
a vertical block
a horizontal block

the horizontal ones need to only move left and right
the vertical ones need to be able to move only up and down.

the problem comes when they collide. when they collide they are forced to move in a different direction:
eg:
if the vertical one collides with the horizontal one the horizontal one gets pushed down.
how can i solve this?

Comments

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Do they have to collide? Could they just overlap? Have you tried constraining their X or Y positions?
  • giacomopoppigiacomopoppi Member, PRO Posts: 914
    yes they must collide, not overlap.
    if i constrain attributes X/Y they don't collide.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    are you constraining positions or motion? Have you tried both?
  • giacomopoppigiacomopoppi Member, PRO Posts: 914
    i did
    timer every 0 seconds
    constrain attribute self position x to mouse position x

    how do i do the motion?

    practically i am "dragging" the actors.
    5 mins and i'll upload a sample for you.
  • giacomopoppigiacomopoppi Member, PRO Posts: 914
    http://gamesalad.com/game/play/33714
    here, try dragging around the blocks.
    see that they get dragged away?
    i need to stop that.
    thx for all your help
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Hey,

    The only piece that can move at any given time is the piece you are dragging. You want all the other blocks to be immovable.

    A quick and dirty way to do it would be like this:

    You could make two versions of each block, one of them would be Movable and the other would not be Movable.

    You'll need to keep track of each block by giving them each an integer attribute. 1,2,3,etc.

    And also a global attribute which is called something like "CurrentSelectedBlock". Initially set it to 0.

    Initially, all the blocks in the Scene are the Movable versions.

    When you click on a block, set the global currentSelectedBlock to the integer of the clicked block.

    In all of the movable blocks, have a rule that says:
    If game.currentSelectedBlock > 0
    If game.currentSelectedBlock does not equal self.myNumber
    Spawn Actor
    (the immovable version of myself)
    Destroy

    When you release the mouse, set currentSelectedBlock back to 0.

    In all of the nonmovable blocks, have a rule that says:
    If game.currentSelectedBlock = 0
    Spawn Actor
    (the movable version of myself)
    Destroy

    Unfortunately, you can't set an Actors movable property on the fly, so you need to make two versions of each block.

    That should work.
    Does that make sense?

    Joe
  • giacomopoppigiacomopoppi Member, PRO Posts: 914
    woah thx for that, i'll try it out properly tonight... got school now :(
    will that work though?, on the scenes ive god vertical blocks and horizontal ones of all lengths.
    ill try it though.
    thx loads :)
  • firemaplegamesfiremaplegames Member Posts: 3,211
    ahh nevermind...

    I just tried it and it doesn't work. Constraining the position of the block to the mouse overrides the collision of the blocks. it just goes right through them.

    Honestly, I think it might be too tough to try and do it this way, (the way that you have it) by using GameSalad's physics engine.

    A better (and easier) way would be to not use the physics system at all...

    I use the same thing here in my slider demo:

    http://gamesalad.com/game/play/30207

    It's not using any collisions to set the limits of the slider. Just two attributes, leftLimit and rightLimit. They can be set to anything. Your game could work similarly.

    You just need to know how far each block can be dragged mathematically.

    There are many ways to do this, but one you could try is to send out invisible "bullets" from the block in both directions when you click on it. When the bullets collide with blocks, the distance between the bullets would be the distance that the block can travel.

    Hope this helps!
    Joe
  • giacomopoppigiacomopoppi Member, PRO Posts: 914
    thx i'll try that too.
    im really grateful for all your help Joe :)
Sign In or Register to comment.