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
Drag and Release
  • Hi 

      Further to my other post , I have been trying to get an object/character to be dragged by following the touch position of the mouse/touch method and then when released it has a catapult effect going forwards. Currently on trying various methods to do this the object has now decided not to appear on screen at all and I have set the Body Type under the spatial to Non-Simulated (KINEMATIC) which it still is. I have even opened another project and re-opened this one but the object still does not appear 

    I only have the following properties:

    two Rules Maps

    The rules maps consist of a move and the other a Interpolate 

    so I am currently getting very frustrated with this as no matter what I try  problems seem to arise


     I have got the object to appear now as the Body Type for one had changed back to dynamic and I had to remove one of the properties for some strange reason even though it had not caused a problem before.

     On the drag and release side I have used the interpolate but I still am struggling with getting the right results from this , please help.


  • 11 Comments sorted by
  • @Lavon

      Thank you for your helpful reply on how to do this, I am not sure though whether my interpolate settings are right as I am not getting the right dragging motion and I do not think I am using the right type of setting e.g. integer , string etc for when I change the gravity, I cannot seem to apply images to this post using my web space and I have checked permissions on the folders and they should allow read for all as I was going to include screen grabs of what I have set to this project

     Also when dragging the movement of the object is either very slow or very jerky any ideas?


  • @TimCS You will need to keep your object as dynamic so you can apply a force to it later. This effect will require turning global gravity on and off at the right time. So here is how you can do it. By default set gravity in the world to 0,0.

    Then add the logic to your object to move it based on the mouse/touch position to drag it. (Sounds like you got that part figured out). 

    Then when the object is released execute a Property Change action and access the gravity on the spatial manager property on the objects spatial. Every spatial has access to the spatialManager of the current scene. This object has various properties on it like the global gravity. Spatial.spatialManager.gravity. That is a Point object so set this property to something like the default gravity (0, 600) to turn gravity back on. Then execute a Physics Impulse action. This will apply a force to the center point of your object and push it in a certain direction. Passing a positive value to the X value will push it to the right. Passing a negative value to the Y value will push the object up the screen. That should achieve the effect you are looking for.
  • Sorry again for posting another reply, could not edit existing post now that a day has past on :)

    I found this thread that has helped in some ways with what I am trying to achieve :

    My only issue that I have now is that with the Move trigger the object does not follow the mouse but if I use the Interpolate property trigger and set the duration (Seconds) to zero I find that the objects appears to "flash" up in the top left hand corner when ever it moves. Any way to stop it from doing this ?

    ** EDIT **

     I have also applied the gravity and Physics Impulse action when the mouse is up but neither does anything at all.  


  • @TimCS no you shouldn't be using a move or interpolate action to move the object while dragging. You just use a constrain property action which will continuously update the position value of the spatial as the two conditions of the drag are true.

    I did find that I had to store the mouse down state in a custom property on the object so that I could check the button down state while checking for mouse moving in the rules component. This is actually a bug because mouse down "on Entity" should always be true once the initial mouse down occurred on the entity even if the mouse has moved off of the entity. As long as the button has not been released yet. This should be fixed in the next build which would eliminate the need for the extra mouseDown property. You will be able to just use the Mouse Down "onEntity" event condition along with the mouse moving event condition.

    I've created a little sample project to show you how this could be done. I put in static values for the impulse applied. However the strength of the impulse applied is affected by the amount of gravity in the scene and needs to be increased or decreased depending on the amount of gravitational force in the scene. You can also affect the strength of the impulse applied based on the distance the player stretches or pulls the object back. So you can use the distance as a multiplier to increase and decrease the strength of the thrust forward.
  • @Lavon

     Thank you for you input and help with this, one thing , I do not seem to be able to download the attached example you have provided . I am trying this on my Mac using Safari so could it be that or do I need to go about this another way?
    ** EDIT 1 **

     Also found why the object/character was not moving after setting the gravity, it appears that even though I set the body type to Dynamic and saved the project, this time it has reverted back to Non-Dymanic , this seems to be happening a lot with this project as to start with I had set it to Non-Dynamic and it had set itself back to DYNAMIC , perhaps an issue with GBS on the latest build?

    ** EDIT 2 **

    Used the constraint trigger as you suggested and this works much better thank you for moving the object/character about. As for the impulse trigger I seem to find that the Y - value has to be greater that the amount of gravity set against the object otherwise it drops off the screen. 

    I could do with looking at your attached example but have yet to find a way of downloading it any thoughts?


  • @Lavon

      Thanks I will take a look at this and hopefully get my head around it all :)

  • @Lavon

       I have looked at your example and from what I have managed now with mine they are similar. However being new to making games on any platform with any software I am probably going to sound stupid in asking more questions on this.

      From your post you mentioned about using the distance of how far the object/character is pulled back to the basis of the gravity. This of course all depends on various factors such as the pulling distance, gravity and direction. My problem is how to determine the direction as well as how to determine the gravity and distance.

     On the mater of the distance I have tried to use the maths expression "distance" for the X and Y co-ordannaces but to know which direction that the object/character should go in is one of my problems and then how would I calculate the basis of the power based on the distance and gravity.

     again sorry for the basic questions here but I am (as you can tell) new to making a game but I have got to learn somehow and your software does seem better suited for me over others that I have tried.


  • @TimCS don't be afraid to ask questions. That is how you learn. It is really simple to achieve. You will just need to start with a base static velocity value and multiply that value by the absolute value of the distance. Then you wrap the whole equation with parenthesis and put a negative sign in front of it to push the object up the screen. Remember to move objects up the screen you have to give negative values in the y coordinate of the object's position or velocity.

    An expression something like this:

    -(500 * abs(distance( X1, Y1, X2, Y2)))

    Wrap the distance helper method result with the abs() helper method so that the calculation returns a number that is not negative.

    This is the idea. I will check this equation later to make sure it works. I'm just running out of my office right now and wanted to get you a response to this.

  • @Lavon

      Thank you for your help, I will try and see if I can get this to work, as for the parameters in the distance helper, I presume the first two are the from and the second two are where it is heading. On that basis, what would I use as the from would I use the spatial.y and spatial.x and as for the too position how would I calculate this? I was trying to do this before my last post but had no success as I was trying to use the distance helper but really didn't know what to enter into the parameters.

    I have tried your suggestion but not getting anywhere with it because of my lack of understanding with this distance helper and what to use for the parameters . I will keep trying but also will await your reply once you have had chance to try this. 

  • @TimCS you should have a starting point where the object being pulled back will originally be located when the level loads. You can use a pre-determined position or you can place a dummy object in that spot and just hide the renderer. You will use that beginning position as the first X and Y param of the distance helper method. Then as the user stretches/drags the object backwards or down the screen you will use the current objects' position as the second X and Y values to get a distance value. You can print that value out to the console using a log action to see what the value is at runtime while testing so you can determine how much you need to increase or decrease that value to actually get the object to move against gravity. The console can be opened at runtime if you run the game in debug mode and you hit the "~" (Tilde) key at runtime. You can also reduce the amount of gravity in the scene if the numbers required are to high.

Howdy, Stranger!

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

In this Discussion