playMaker

Author Topic: Relative touch control for shmup - best practice? [SOLVED]  (Read 6770 times)

ultimate_carl

  • Playmaker Newbie
  • *
  • Posts: 12
Relative touch control for shmup - best practice? [SOLVED]
« on: April 10, 2017, 03:25:22 PM »
Hi, I'm making a (2D) shoot-em-up with relative touch control (i.e., touch anywhere on screen to move ship independent of touch point; NOT the ship jumping to where the touch is). My FSM/actions right now:

  • Touch Event for initial touch & change state when moved
  • In next state, Get Touch Info to store positions & deltas
    • Float Multiply the X & Y deltas to increase ship speed
    • Translate the deltas (in Self space, Fixed Update)
    • ...and Touch Event when Ended and go back
    (All on every frame where applicable)

    This works fine, but not 100% how I expected. The problem is the ship drifts after increased movement. So, if I touch right on the center of the ship and go back and forth (L-R) a little bit, then the ship's alignment ends up off to the side of the finger.

    In other mobile shmups I play with this control type, the ship always stays at the center of the touch point regardless of activity/speed, and that's the result I want. I've tweaked the delta multiplication several times (around 20-95), but that doesn't "tighten it up" any better.

    I've seen many pages about Unity's touch input tried different PM actions, but it seems few people directly address this genre and control type. (I've also played with Screen to World Point, but the solutions related to that are designed for absolute/jump-to control, which I don't want.) Am I using the deltas wrong? Should I involve deltaTime somehow? Should I use more math? Any thoughts welcome.
« Last Edit: May 27, 2017, 08:23:23 PM by ultimate_carl »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Relative touch control for shmup - best practice?
« Reply #1 on: April 11, 2017, 01:50:55 AM »
Hi,

 It's because you need to record the delta position at the time of the touch and keep that delta as something you add to the touch movement. so if your touch has moved 2 pixels to the right, you also need to substract the delta movement and this will get rid of the jumping.

 Bye,

 Jean

ultimate_carl

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Relative touch control for shmup - best practice?
« Reply #2 on: April 11, 2017, 04:08:30 PM »
Hey Jean, appreciate your help.

OK, I'm storing the start of the touch, but I'm not clear on the rest. Am I adding the start delta to the current delta? But then also subtracting it from something? Can you elaborate, maybe list the right steps/actions? Thanks.
« Last Edit: April 11, 2017, 04:28:48 PM by ultimate_carl »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Relative touch control for shmup - best practice?
« Reply #3 on: April 12, 2017, 02:42:40 AM »
Hi,

 no, you would instead use the absolute position of the touch and substract to that the original delta when touch began and then you can't have drifts anymore.

Make sense?

Bye,

 Jean

ultimate_carl

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Relative touch control for shmup - best practice?
« Reply #4 on: April 12, 2017, 09:30:57 PM »
It makes sense, but now I don't know how to get PM to pull it off correctly.

i.e., I do Xpos - previousXDelta = newDelta and the ship just zooms up diagonally when finger moves.
I do Xpos - previousXpos = newDelta and the ship floats around constantly like pulling a balloon.

I haven't changed the end of the state (Translate the deltas), so if I need to use something else, let me know. Everything's normalized and on every frame.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Relative touch control for shmup - best practice?
« Reply #5 on: April 13, 2017, 02:37:56 AM »
Hi,

 yes, it's typical behavior when things go wrong on dragging :) I'll let you struggle for this week  :P get back to me on monday and if you haven't solved this I'll do a working sample ok?

hint: if it zooms of it's because you  likely keep adding the offset to the base instead of saving base -offset to a new variable that is the final position. also check your everyframe setup, maybe you don't need everyframe depending on how your state is entered and exited. if your state is entered every frame during the touch life time, don't use "every frame" actions.

 Bye,

 Jean

ultimate_carl

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Relative touch control for shmup - best practice?
« Reply #6 on: April 16, 2017, 11:53:36 PM »
It zooms away because it was every frame, but if I turn that off, it can't move anyway. So yeah, sorry! It's been such a trouble trying to find references/solutions for this exact issue that I just don't know how to configure PlayMaker for it.

Here's my template - it's what I originally said works but with drifting.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Relative touch control for shmup - best practice?
« Reply #7 on: April 18, 2017, 02:03:41 AM »
Hi,


 ok, I'll have a go at this, but please bump me towards end of week ok?

 Bye,

 Jean

ultimate_carl

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Relative touch control for shmup - best practice?
« Reply #8 on: April 22, 2017, 04:36:06 PM »
Bump! Still haven't made much progress. Thanks in advance for taking a look though.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Relative touch control for shmup - best practice?
« Reply #9 on: April 26, 2017, 03:44:33 AM »
Hi,

 ok, I'll get on this and create a small demo. Please bump me mid next week if I haven't got back with it :)

 Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Relative touch control for shmup - best practice?
« Reply #10 on: May 02, 2017, 04:05:22 AM »
Hi,

 Ok, I have done the sample, I went for another approach with I feel is going to give you a lot more options, so this one accepts both mouse Input and Touch Input ( just disable mouse input if you don't need it), and it uses a target GameObject for the Ship to move towards to, which is easier to debug and gives you more control over the movement itself ( speed for example).



 Let me know how it works out for you, Check out the touch fsm and see how I watch for a touch begin event, and store the fingerID related to it to late reuse that FingerID to check for that touch specifically ( in case you are using multi touch inputs).

Let me know if you have questions

 Bye,

 Jean

ultimate_carl

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Relative touch control for shmup - best practice?
« Reply #11 on: May 17, 2017, 02:13:45 AM »
Sorry for the late reply; got distracted with other project parts. :P

I appreciate the package and it's a good approach. however, I'm not looking for "move towards" or similar behavior -- no matter where the touch/click stops or starts, the ship should move from its own position, not jump to where the touch point is.

For a real world example, this free little game does what I want: https://play.google.com/store/apps/details?id=com.security16bit.ccs

Thanks nonetheless!

ultimate_carl

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Relative touch control for shmup - best practice?
« Reply #12 on: May 27, 2017, 08:23:14 PM »
OK, I think I found something I'm satisfied with, after going back to study more example games and adjusting my expectations  :)

Attached is the template, but basically here's the recipe:
  • State 1- On mouse button down ->
  • State 2-
    Get Mouse Delta: save separate X&Y values; normalize
    Float Multiply XDelta by 10 and YDelta by 20 (<- optional values, they're just my sweet spot); every frame
    Translate those X&Y deltas; every frame
  • Return to state 1 on Mouse Button Up

Naturally, the mouse-specific actions can be replaced with Touch Event and Get Touch Info, respectively.

For my game, I also assign Set Animator Float to the XDelta, which is tied to an Animator parameter I use to do ship "lean" animations, then reset that in state 1.
« Last Edit: July 10, 2017, 02:28:00 PM by ultimate_carl »