playMaker

Author Topic: throwing a ball (object) with swipe gesture  (Read 7904 times)

merde10

  • Playmaker Newbie
  • *
  • Posts: 46
  • new user of playmaker :)
    • View Profile
throwing a ball (object) with swipe gesture
« 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 :)
« Last Edit: June 07, 2016, 07:38:58 AM by merde10 »

Zeldag

  • Full Member
  • ***
  • Posts: 198
    • View Profile
Re: throwing a ball (object)
« Reply #1 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...
« Last Edit: May 26, 2016, 02:57:41 PM by Zeldag »

merde10

  • Playmaker Newbie
  • *
  • Posts: 46
  • new user of playmaker :)
    • View Profile
Re: throwing a ball (object)
« Reply #2 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?

PolyMad

  • Sr. Member
  • ****
  • Posts: 412
    • View Profile
Re: throwing a ball (object)
« Reply #3 on: May 26, 2016, 05:04:25 PM »
Probably better ADD FORCE than SET VELOCITY.

merde10

  • Playmaker Newbie
  • *
  • Posts: 46
  • new user of playmaker :)
    • View Profile
Re: throwing a ball (object)
« Reply #4 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?

PolyMad

  • Sr. Member
  • ****
  • Posts: 412
    • View Profile
Re: throwing a ball (object)
« Reply #5 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.

merde10

  • Playmaker Newbie
  • *
  • Posts: 46
  • new user of playmaker :)
    • View Profile
Re: throwing a ball (object)
« Reply #6 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).

merde10

  • Playmaker Newbie
  • *
  • Posts: 46
  • new user of playmaker :)
    • View Profile
Re: throwing a ball (object)
« Reply #7 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.

PolyMad

  • Sr. Member
  • ****
  • Posts: 412
    • View Profile
Re: throwing a ball (object)
« Reply #8 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.

merde10

  • Playmaker Newbie
  • *
  • Posts: 46
  • new user of playmaker :)
    • View Profile
Re: throwing a ball (object)
« Reply #9 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.

PolyMad

  • Sr. Member
  • ****
  • Posts: 412
    • View Profile
Re: throwing a ball (object)
« Reply #10 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.

merde10

  • Playmaker Newbie
  • *
  • Posts: 46
  • new user of playmaker :)
    • View Profile
Re: throwing a ball (object)
« Reply #11 on: May 27, 2016, 01:42:24 PM »
how can i do that?

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • View Profile
    • Can't code? Who cares! Make games anyway!
Re: throwing a ball (object)
« Reply #12 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-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

merde10

  • Playmaker Newbie
  • *
  • Posts: 46
  • new user of playmaker :)
    • View Profile
Re: throwing a ball (object)
« Reply #13 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)?
« Last Edit: May 28, 2016, 11:21:54 AM by merde10 »

PolyMad

  • Sr. Member
  • ****
  • Posts: 412
    • View Profile
Re: throwing a ball (object)
« Reply #14 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!