Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: merde10 on May 26, 2016, 10:06:24 AM

Title: throwing a ball (object) with swipe gesture
Post by: merde10 on May 26, 2016, 10:06:24 AM
Hello guys,

i just started a new game (a basketball shoot), and i would like to know how can i use playmaker for throwing a ball (object), with the swipe gesture?

I search for a tutorial but i didn't found one.

Thanks a lot :)
Title: Re: throwing a ball (object)
Post by: Zeldag on May 26, 2016, 02:35:28 PM
Hi,

I've never done this myself, but I can imagine it working like this, just think of this more as basic summary of something you could try, rather than an actual solution/tutorial:

In state 1 use 'swipe gesture event' action, make it transition into state2.

In state 2 you can simply 'add velocity' to your object, in the desired directions and it will be thrown.

Or I believe (i should say i guess really) you could do what is below to make distance thrown dependant on the swipe length:

In state 2 use the 'get touch info' actions to 'store delta y' into a float variable (you may, or may not, want to click the 'normalize' box in this action). Then use set velocity (or possibly add force) action to move your object, you can set the float from delta y to make the velocity dependant on the distances Swiped.

Good luck with it and I hope this helps. Also I hope it is right, as Ive not done it myself...
Title: Re: throwing a ball (object)
Post by: merde10 on May 26, 2016, 04:51:56 PM
hey, thank you for your tips :)

I just manage to do what i want but i have some issues.

I create an empty GameObject, which i add a FSM.

I create a state 1 "swipe gesture":

  - i put a "Touch Info" (Touch Phase = Ended)

  - and a "Get Touch Info" where i store Delta X and Delta Y into 2 float's variables (x and y).


Next i set up a state 2 "create ball":

  - i put a "create object" event, where i put my ball as a gameobject.

  - and a "Set Velocity" where i select "x variable" for X, and "y variable" for Z.

  - and a "Add Torque" (for the rotation spin), which i add -200 for X.

Then a state 3 with a "wait" event (0.5).

So actually, when i swipe my screen, a ball appear but there is no force added. The ball simply drop. And when i swipe again, another ball appear and drops too, ect...

there is no shoot lol what do i miss?
Title: Re: throwing a ball (object)
Post by: PolyMad on May 26, 2016, 05:04:25 PM
Probably better ADD FORCE than SET VELOCITY.
Title: Re: throwing a ball (object)
Post by: merde10 on May 27, 2016, 06:19:05 AM
When i replace it as you said, i had the same problem...

I don't know why?
Title: Re: throwing a ball (object)
Post by: PolyMad on May 27, 2016, 06:49:08 AM
How much force are you adding?

Try to make it simple: place a sphere in the middle of the map, in front of the camera.
Add a FSM that adds a force to it. Only that.
When the map starts, you should see the ball move.
If this doesn't happen, then there's some problem.
But this way you can find your problem probably.
Title: Re: throwing a ball (object)
Post by: merde10 on May 27, 2016, 07:08:37 AM
well i don't add a value, i just check the box value with x and y float variable (store the touch info).
Title: Re: throwing a ball (object)
Post by: merde10 on May 27, 2016, 07:16:51 AM
I just saw that the value of my x and y float variable are very low (like 0,1).

So i create a new state "multiply", where i put my float variables and multiply by 10 and now the force works.

But now i saw that just the first ball to appear have the effects of force, but next balls don't have force they just dropped, and the force continue to push the first ball.
Title: Re: throwing a ball (object)
Post by: PolyMad on May 27, 2016, 07:23:46 AM
If I was you I would do it this way:
FSM on the ball, when the ball spawns, X force is added, Y rotation is added, end of story.
FSM on the player character that gets the direction and puts it in a variable, when the player shoots the ball, you make the ball spawn using this direction vector.
Done.
Title: Re: throwing a ball (object)
Post by: merde10 on May 27, 2016, 08:27:10 AM
thanks it works but for the direction is the same for all balls.

Even when i touch the screen instead of a swipe, the ball had the same direction.
Title: Re: throwing a ball (object)
Post by: PolyMad on May 27, 2016, 10:22:25 AM
Eh, you have to give the user a way to choose where he wants to shoot, I guess, otherwise the force will always be applied in the same direction.
Title: Re: throwing a ball (object)
Post by: merde10 on May 27, 2016, 01:42:24 PM
how can i do that?
Title: Re: throwing a ball (object)
Post by: mdotstrange on May 27, 2016, 07:44:02 PM
What I usually do is this- I use Add Force on the object that is the "ball"- it is set to Self, I use the "impulse" force type and I add the force on the Z axis only-

I have an empty game object I call "shooter"- I use a look at action to have the shooter look at the target- I then spawn/create the ball object at the position+rotation of the shooter- it then fires the balls at the target-
Title: Re: throwing a ball (object)
Post by: merde10 on May 28, 2016, 10:12:23 AM
The player has to move, or rotate in order to work? and can i adjust the force added in y axis with the swipe y gesture (with your method)?
Title: Re: throwing a ball (object)
Post by: PolyMad on May 29, 2016, 11:12:24 AM
Soooo... listen, programming is something that one has to really really really want to do, or there's no way to go on with it.
Now, you have to think, WHAT you want the player to do, and HOW to convert the sequence into programming.
You want that the player drags his finger on the screen so he can rotate the view to a certain angle, I imagine, so you search in PlayMaker for the actions to drag on touchscreen, you can easily search for actions by typing some letters of what you want when you are adding an action. On top of the window is the search field.
Then maybe you make the window slowly oscillate when the player must launch the ball, so you have to look for vector settings and movement.
It's not so easy, and even a project that may look simple like this one will require effort if it's your first programming experience. Maybe it's too difficult to start with it!
Title: Re: throwing a ball (object)
Post by: merde10 on June 03, 2016, 08:58:51 AM
i know what you mean and i understand.

i just found a solution. But i have two more issues. So when i swipe on my screen, the ball follows the direction of my swipe like i wanted.

but:

- when i tap my screen, it adds force along the y axis, and it's very easy to score. So i add a "swipe gesture event" state, before "touch event" and "get touch info" state, so
 the player must have to swipe to shoot, but by doing this, i need to swipe 2 times to shoot.
I also put the "swipe gesture event" into the same state, but when i tap it shoots lol.

- the detection of the shoot along x axis is weird. For example, when i swipe to the right, the shoot follows the swipe gesture. But when i swipe to the other side (left), it shoots up.

(i test that with unity remote).



Title: Re: throwing a ball (object)
Post by: PolyMad on June 03, 2016, 09:08:27 AM
I can't help with the swipe gestures, as I have no experience with them.
About the strange behaviour shooting right ok, but shooting up when swiping left, check the axis of the ball when it spawns, or whatever method you are using to spawn the ball and also the direction of the force applied. It's very probably something to do with inconsistence in these things.
Title: Re: throwing a ball (object)
Post by: merde10 on June 07, 2016, 07:38:23 AM
I think it's about when it store the x value, because when i see the x value when i "swipe" it's completely weird.

Also i build the game to see on my device how it looks, and the x axis doesn't to work, it only shoots on the y axis.
Title: Re: throwing a ball (object) with swipe gesture
Post by: PolyMad on June 07, 2016, 08:23:28 AM
I imagine you are swiping from the bottom of the screen up.
This is why Y is growing but X is probably just oscillating on low values.
You should understand how X changes when you swipe, to correct the problem, there's no shorter way.
Title: Re: throwing a ball (object) with swipe gesture
Post by: merde10 on June 07, 2016, 08:42:18 AM
yes, this is why i add a multiply state to increase the x value, it works on the remote app, but not on my device when i build the game.
Title: Re: throwing a ball (object) with swipe gesture
Post by: PolyMad on June 07, 2016, 09:18:52 AM
Deh this is that kind of problem that can drive you crazy... different behaviour based on the devices... good luck with that, I can't help here  :D