Touch & Drag to Aim, Release to Fire?

0 favourites
  • 10 posts
From the Asset Store
Make your own platformer for both the web and mobile easy with this Santas Platformer Template, FULLY DOCUMENTED
  • First things first, want to say thank you to everyone on the forum. I'm brand new to C2 and everyone has been incredibly helpful. Really appreciate it.

    I'm looking to create an action for a touch based game. The idea is if you touch the sprite and drag your finger away from it, the ability to aim will be enabled in the opposite direction. A similar idea is found in the game Gersundheit. The plan is to use it as a sort of whip to collect tokens.

    I have spent the last week trying different combinations and searching the forum and can't seem to find any solution. Could anyone point me in the right direction?

    Thanks!

  • I would make 4 variables.

    StartX

    StartY

    EndX

    EndY

    On touch begin, I would set StartX and StartY as Touch.X and Touch.Y.

    On touch end, I would set EndX and EndY as Touch.X and Touch.Y once again.

    What I'd have had there would be the start and end of my drag. From there I could use the angle(StartX,StartY,EndX,EndY) to find the angle the player has drawn. From there, I can launch the projectile to the Angle I just calculated. If it's inverse or anything like that, you could just use -(angle(StartX,StartY,EndX,EndY)) or something mathematical along that lines.

    <img src="smileys/smiley1.gif" border="0" align="middle" /> Hope this helps!

  • Rory, thanks for the quick response! I'll give it a test right now. Really appreciate it.

  • Have a look at the "Physics Catapult" template.

  • YOu should also base your velocity on some type of multiplier of the distance the item has been pulled from the starting position.

  • Yeap BluePhaze is right, you can calculate that with distance(StartX,StartY,EndX,End.Y) :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Really appreciate all the tips!

    I worked on it last night and got pretty far with a combination of the suggestions you all gave. I can aim by touch and drag on the player sprite and fire when the touch/dragged is removed.

    The problem I am now running into is with the navigation. I need to be able to use pathfinding to find a path to a touch, however when I do so, the player sprite fires.

    Can't seem to find a way to separate the two events without getting one (or the other) to stop functioning.

    Here is my first capx (it's rough): docs.google.com/file/d/0BwBgS0CgFcUdMXJ6WjBXRVhxSWs/edit

  • Again, really, really appreciate all the help!

    My mind has been blown by Construct 2.

  • use a variable set the current state, have one for firing and one for target location. activate/deactivate your events based on the variable

  • Good call... I'll give it a test tomorrow. Thanks!

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