[SOLVED] Move Sprite at angle following mouse's movement

0 favourites
  • 10 posts
From the Asset Store
3D Car Pack 1
$2.99 USD
3D models + Rendered Low-Poly Cars in isometric, top-down, and side angles.
  • Hey everybody, been stuck with this for a while.

    Following scenario:

    I'm building a (very) simple pool game. Currently, I'm setting up the basic control of the queue.

    Basically, what I'm trying to do is this:

    • When the mouse button is pressed, the queue's angle gets locked (no problemo)
    • the queue gets moved on its current angle according to the distance the mouse gets moved while the mouse button is pressed (here is the issue)
    • the queue should just be movable in one direction

    I figured, I have to do some sinus and cosinus callculations to be able to perform this for every possible queue angle.

    I worked out some solutions, experimented a bit with lerp, but in the end, I couldn't combine both x and y coordinates. One on its own (obviously) wouldn't be much of a problem.

    If there would be a way to combine both X and Y distance of the Mouse, then I could use the "move forward" action for the queue..

    Did I explain well what I'm up to?

    If not, I'm happy to explain if there are questions.

    As always, anyy help is aprecciated.

    Thank you.

  • You just set a co-ord into a variable for initial touchxy. Assuming you already have the angle for the cue set to i.e. 0, I would then move the cue at angle 0 every tick (position + the distance between current touchxy and initial touchxy. ) So if you're holding down and have dragged 50 pixels then the cue moves at angle 0 for 50 pixels, the distance between initial touch and current touch. Also it's a CUE, if you're making a pool game

  • Good to know, thought it was spelled differently <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

    Your solution seems pretty obvious.

    Though how should I calculate the variable of the distance containing both X and Y coordinates?

    Maybe, I wasn't clear enough:

    I don't want the cue to follow the mouse. Assuming the cue is at angle 0 for example, in that case I would want it to just follow the x movement of the mouse.

    If the cue was at 90 degrees, just the Y movement.

    And at 45 degrees for example, a combination of X and Y.

    This combination is what bugs me.

    Since I'm no native English speaker, my intentions may not seem too obvious. <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

    Maybe this is easier to understand:

    When the mouse button is down, I want the cue to follow the mouse, but at the same time, the cue should be restricted to only move on a line having the current cue's angle.

    (As if it had the drag and drop behaviour and there were walls parallel to the cue)

    Could also be possible that I misunderstood your solution.

    I uploaded my .capx here: https://www.dropbox.com/s/aemopym3697i7 ... .capx?dl=1

    Maybe you can just download it, edit it and upload the working result so that I can understand your solution. <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    (all the disabled events are what I tried to geet it to work)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well my method would work if the angle was predefined and wasn't open to change. Sounds like you want it to update the cue's angle constantly based on the angle that themouse is moving at so I guess yeah you'll have to do some maths here and calculate some angles. Good luck! xD I'm sure someone could come up with a solution tbh, maybe I could after some sleep.

  • Just to clarify this: as soon as the dragging starts, the angle of the cue stays constant.

  • something like this ?

    angleLock.capx

  • korbaach

    Are you Jesus?

    That is brilliant and exactly what I need.

    Obviously, I didn't see that I need to divide the distance by 2...(any easy-to-understand explanation for that to make a math noob understand what he is implementing in his project?)

    And I forgot about the "distance" expression.

    Thank you very much, this thread is SOLVED!

    (Also, thank you very much for your posts. )

  • Ah very nice, I made an attempt but I couldn't do it that well, I'm more of a debugger than a maths wizard.

  • Still appreciate your efforts, thank you. :)

  • something like this ?

    angleLock.capx

    Wow. I think you may have just helped me solve a problem for one of my own games builds. Thanks...?!?!?!

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