Multi-Resolution Game Development With GameBuilder Studio Check it out!
NEW Version 0.9.7 has arrived! New Blazing Fast Particle Engine & More Game Actions. Check it out
Moving multiple spatials on X-axis only or Y-axis only
  • Here is an example of what I am trying to work out:

    image

    I have the dummy objects with a spatial on them set as Dynamic, and turned the Global Gravity to zero (0).

    To get the Yellow box to move on the Y-axis when Touch is Down I set up a RulesMap component that checks for When the Touch is Down on the entity. The trigger a constrain action:
    @Spatial.y =  Self.Spatial.y - ((Self.Spatial.y - Game.Touch.TouchPoint1.y) * 0.9)

    This allows the yellow box to move along the Y-axis. I can switch out the y's for x's when wanting to move the Green box for example on the X-axis.( as I will want to be able to move certain boxes only on the X-axis and others only on the Y-axis)

    What I am trying to accomplish is that when the Yellow box is moved and collides with the Green box is:
     1) not allow any further movement of the yellow box on the Y-axis because the Green box is in the way  
     2)Prevent the Green box from moving at all when the Yellow box bumps up against it.

    I have tried using Change Property actions to change the bodyType of an object to STATIC (set as a string)when the touch is Up and also tried unchecking canMove in the spatial settings of the objects. No luck. Wondering if there is a way to Constrain a spatial to an X or Y-axis?

    Has anyone been successful with something like this?



  • 2 Comments sorted by
  • @BenFromOregon whatever logic (rules) you have to constrain the movement of the box to touch point can be toggled on and off by just adding another condition to the drag logic and having two properties. xMovementEnabled, and yMovementEnabled. That way you can turn each movement axis on / off independently so the object only moves in a certain direction when enabled.

    To get the boxes to not move but still get collisions just turn them into sensors and they won't interact with each other physically but you will get a collision event when they collide.
  • @Lavon Right in front of my face! Thanks Lavon you are the best.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Tagged