Distance between two points problem.

  • Hi guys,

    I expect the player to be able to touch a sprite, drag and release to determine the direction and force to launch the sprite. So the further away I drag the greater the force in the direction of the touch end.

    However, I find that the force seems to be inconsistent to if I drag left and release compared to when I drag right and release.

    I have attached the capx so you friendly people can help my find out what I've missed.

    My thoughts at the moment at potential problems are maybe different co-ordinate systems or taking touch co-ordinates incorrectly or at the wrong time? Thoughts?

    Kind regards,

    Wyrm

  • A few more details.

    -Dragging from the sprite to top left produces small distances than dragging to the top.

    -Sometimes the sprite can get stuck. Just refresh and try again.

  • and a general observation that i noticed is the further right the sprite is in the scene the greater the resulting distance.

  • Ok guy, I post you my version of what your are expecting.

    I guess you looking too complicated ^^

    Hope it help

  • Thanks you're a star. So essentially you used absolute position of the touch on start and again at touch end. Where absolute refers to the current position of a touch over the canvas area. So I may use this as it side steps the problem.

    HOWEVER, I am still interested in why my original doesn't work to further my knowledge. Anybody have any ideas?

  • Maybe just a little error ^^

    When you make this action :

    Set GobalDistance to distance(Player.X,Touch.X,Player.Y,Touch.Y)[/code:3aznd5pr]
    
    If you read carrefully the documentation, you see : 
    
    [quote:3aznd5pr]distance(x1, y1, x2, y2) Calculate distance between to points
    
    
    So you probably just have to invert y1 and x2 in you expression : 
    
    [code:3aznd5pr]distance(Player.X,Player.X,Touch.Y,Touch.Y)[/code:3aznd5pr]
    
    And it solve the problem ô/
    
    PS:After that, for me the block never get stuck another time O_o
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • ah ok, that explains it! I assumed it was the same as the math order!

    Good spot! Thanks again!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)