Playmaker Forum

PlayMaker Help & Tips => Android Help => Topic started by: ultimate_carl on April 10, 2017, 03:25:22 PM

Title: Relative touch control for shmup - best practice? [SOLVED]
Post by: ultimate_carl 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:

Title: Re: Relative touch control for shmup - best practice?
Post by: jeanfabre 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
Title: Re: Relative touch control for shmup - best practice?
Post by: ultimate_carl 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.
Title: Re: Relative touch control for shmup - best practice?
Post by: jeanfabre 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
Title: Re: Relative touch control for shmup - best practice?
Post by: ultimate_carl 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.
Title: Re: Relative touch control for shmup - best practice?
Post by: jeanfabre 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
Title: Re: Relative touch control for shmup - best practice?
Post by: ultimate_carl 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.
Title: Re: Relative touch control for shmup - best practice?
Post by: jeanfabre 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
Title: Re: Relative touch control for shmup - best practice?
Post by: ultimate_carl on April 22, 2017, 04:36:06 PM
Bump! Still haven't made much progress. Thanks in advance for taking a look though.
Title: Re: Relative touch control for shmup - best practice?
Post by: jeanfabre 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
Title: Re: Relative touch control for shmup - best practice?
Post by: jeanfabre on May 02, 2017, 04:05:22 AM
Hi,

 Ok, I have done the sample (https://twitter.com/JeanAtPlayMaker/status/859317414135246848), 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).

(https://pbs.twimg.com/media/C-zo0i5W0AAa92c.jpg)

 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
Title: Re: Relative touch control for shmup - best practice?
Post by: ultimate_carl 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!
Title: Re: Relative touch control for shmup - best practice?
Post by: ultimate_carl 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:

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.