#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# My swipe is bent, but thats okay...

Posts: 494Member, BASIC

So i remember finding @Armelline 's "swipe factory" many moons ago and thinking to myself how could anyone ever need any more than that.

But as with so many things the day is upon me.

What if i want to know if the swipe was curved? I know ask a lot, but i thought this might be the day for it, being Christmas and all...

• Posts: 11,310Member, Sous Chef, PRO, Senior Sous-Chef

The easy thing about a linear (straight) swipe is that it has a starting point and an ending point and we really don't care what happens in the middle. Because a straight line has the same slope (direction) along its entire length. So we just detect the start, detect the end, and assume it's straight in-between.

With a curve, you'd have to detect the touch position at several points along the path and then determine the approximate curve (equation) for those points. No, I don't have a Christmas miracle (aka demo) for you but that's where I'd start.

New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

• London, UK.Posts: 12,821Member
edited December 2017

@smurfted said:
What if i want to know if the swipe was curved?

'Curved' is such a vague term, I'm not sure you'll get a definitive answer without being more specific, what precisely does curved mean in this context ?

• Encounter Bay, South AustraliaPosts: 1,362Member, BASIC

@Socks said:

See what happens if you are "naughty and not nice", Santa Clause will take you down.

GS team... are you listening?

• Posts: 494Member, BASIC

Love the tree.

To be more specific i mean a swipe beginning in one direction (say 90 degrees) but ending in an swipe that was traveling in a 30 degree angled deirection. For say bending the direction of a football or a hockey puck.

• London, UK.Posts: 12,821Member

@smurfted said:
To be more specific i mean a swipe beginning in one direction (say 90 degrees) . . .

So starting by swiping up (90°) . . .

@smurfted said:
but ending in an swipe that was traveling in a 30 degree angled deirection.

. . . and then swiping up and to the right ? Is that 30° from the point where you stop swiping up and start swiping right, or 30° from the original start point ?

Maybe a quick drawing would help here.

• Posts: 494Member, BASIC

the angles were just off the top of my head. Though i will endeavour to put pen to paper to explain myself better...

• Posts: 494Member, BASIC

• London, UK.Posts: 12,821Member
edited December 2017

Hmmmmm . . . interesting problem . . . Maybe you could do it like this.

You have two actors, a Controller and a Detector, also make yourself three attributes (real) for the Controller, StartX, StartY and Angle.

Ok . . . As soon as the screen is touched - in the Controller actor record the position of the touch (change StartX to mouseX, change StartY to mouseY . . .)

Now after a very brief time, long enough for the player's finger to have moved away from the initial touch position - let's say 1/10th second (the red cross on the picture below) - measure the angle of the current position from the initial position . . . . and record that into the Angle attribute, like this . . . Change Angle to . . . Vector to angle (mouseX - StartX, mouseY - StartY)

Ok, so we have just captured the direction the player's finger is moving in . . . and saved it as 'Angle'.

Ok, now spawn the Detector actor (big blue rectangle in the image below) position it so it starts at the initial touch position and is angled along the direction of the initial swipe . . . like this . . .

You can do that by using a bit of trigonometry, I am going to say the Detector actor is 800 pixels wide and 300 pixels high . . .

So . . . spawn actor Detector // Direction = 'Angle' (relative to scene) // X position = 400 `*`Cos(Angle)+StartX (relative to scene) // Y position = 400 `*`Sin(Angle)+StartY (relative to scene)

. . . . . . . . . . . . . . . .

Ok so we have a big fat actor laying along the direction of the player's initial swipe direction, now we want to detect whether the player finishes their swipe inside or outside of that area (the big far detector). If they finish inside we can call that a straight swipe, if they finish outside we can call that a curved swipe.

So, in the detector, we have a rule:

When mouse button is up and when mouse position is outside
--We have a curved swipe and so stick some curved swipe rules in here.

• Posts: 494Member, BASIC

Like the button says, "Awesome"...

• Posts: 2,793Member, Sous Chef, PRO

Another way -- in addition to @Socks' excellent suggestion -- is to add different forces to the trajectory of the ball. (Remember, the trajectory of an object is the sum of all the forces acting on it.) The accelerate behavior works great to simulate forces such as wind.

• Posts: 494Member, BASIC

You mean to link an object to the finger then track the motion?

• Posts: 2,793Member, Sous Chef, PRO

Track the motion -- yes.
But you don't necessarily need to link an object.

Here is an example that uses accelerate to 'influence' the trajectory of the actor.

• London, UKPosts: 2,282Member
edited December 2017

@RThurman said:
But you don't necessarily need to link an object.

I think that what @smurfted is looking for is slightly different -- he wants to know how to read a curved finger swipe, so that the ball curves according to the swipe's curve. I guess the sideways force takes over gradually. In your demo, the ball starts moving straight away and then when you swipe sideways, it goes diagonally.

I think the goal is for the whole swipe to happen first and then the ball to move afterwards, with a gradually strengthening curve -- correct me if I'm earn @smurfted.

• Posts: 2,793Member, Sous Chef, PRO

@pHghost -- Oh! Define a path and then have the actor follow it? Yes that would be different.

In that case one way would be to record (in a table) the touch.x,touch.y coordinates of the swipe and then move the actor to each successive x,y position.

• Posts: 494Member, BASIC

Cheers for the input guys. Yes the ball doesn't quite do what the swipe is asking in your example @RThurman. Maybe i should record finger locations like you said...

• Posts: 2,793Member, Sous Chef, PRO

@smurfted said:
Cheers for the input guys. Yes the ball doesn't quite do what the swipe is asking in your example @RThurman. Maybe i should record finger locations like you said...

Yes -- the example was just a bare minimum stab at the idea. It was really meant to show a possible approach. You can get more interesting results if you tinker with it a bit. For example, you can duplicate the accelerate behavior a couple more times, and it will behave slightly differently. Or you can increase or decrease the multiplier in the expression. Or any other number of 'influences' on the actor.

Perhaps if you go into a little more detail -- it might spur an extra idea or two.