Drag your finger from point A to B and make path?

Hello to GS Community,

I am racking my brains on how to drag your finger from point A to point B and make a path, but if your finger doesn't reach point B to destroy the path. The "path" should keep its axis Y, extend its axis X depending on how far the finger goes from point A and rotate if the direction of the finger change. I have drawn simple picture of what I really mean.

image

Thank you in advance

Comments

  • BonepileGamesBonepileGames Member Posts: 194
    edited August 2014

    I have made a progression


    1. When clicked on Point A a path is spawned.


    2. The path changes its self.size.X wherever the touch is.


    I have difficulties in "coding" of rotating the path so the be in the direction of the "finger".

  • ImNiklasImNiklas Member Posts: 103

    What you want to rotate is the vectorToAngle function. I think this would work.

    When Mousebutton is Down:
    --Constrain Attribute self.rotation to vectorToAngle(game.mouseButton.X-game.pointAX, game.mouseButton.Y-game.pointAY)

    I'm not sure it will be right, so you might have to change so it will be pointA-mouseButton position instead.

    Hopefully this will work. Good luck with your game :)

  • BonepileGamesBonepileGames Member Posts: 194
    edited August 2014

    @ImNiklas‌

    That helped a lot! The only setback remaining is the expression for constraining path's size.x

    I initially did that:

    constrain self.size.x to game.touch.x - game.pointa.x

    While moving your finger on the same Y axis, this works wonderful, but if I move the finger upwards, on the same X axis - the path isnt the size it should be.

    So I thought of Pythagoras theorem - A^2 + B^2 = C^2 - where:

    * A is (game.touch.x - game.pointa.x)

    * B is (game.touch.y - game.pointa.y)

    * C is (SHOULD be the exact size of path)


    However, I can't seem to find a way to transform C^2 to C since the path size now is doubled of the ^2.

  • BonepileGamesBonepileGames Member Posts: 194
    edited August 2014

    I made it work.

    If someone in the future is interested -

    Path:

    constrain self.size.width to magnitude((game.touch.x - game.point.x), (game.touch.y - game.point.y))

    constrain self.position.x to (game.touch.x/2)+(object's width of the spawner/2)

    constrain self.rotation to vectorToAngle ((game.point.x - game.touch.x), (game.point.y - game.touch.y))

    constrain self.position.y to (game.touch.y/2)+(object's height of the spawner)

    One object to constrain touch.x and y to a game.rule

    Thank you, ImNiklas.

Sign In or Register to comment.