###

» Thu Jun 18, 2015 11:08 am

Ok so it's like this.

While the player is touching the screen (Is in touch condition)

The pig will have it's angle changed to : angle(Touch.X, Touch.Y, CatapultBlock.X, CatapultBlock.Y)

Which is the angle between the touch coordinates and the catapult coordinates, this will make the pig spin around the catapult depending on where you are touching.

And no only that but the pig will leave the catapult and move a certain distance at a certain angle

So we have this line:

min(distance(Touch.X, Touch.Y, CatapultBlock.X, CatapultBlock.Y) / 3, 45)

where

Min() will return the minimum value between A and B

And Distance() Calculate the distance between 4 points

So the pig will move at a certain distance depending on where the player is touching, however this distance will never be greater than 45, because the pig will move the MINIMUM value between the distance and 45 (Distance() , 45)

And you have the Angle Parameter: Self.Angle + 180

So, every object starts with the initial angle of 0. So if you touch the screen in the exactly position of the catapult, the angle between touch and the catapult coordinates will still be zero, however and angle of 0 moves the object to the right.

You can remove the +180 from the code and watch how the game behaves, you will push the pig back, but it'll go ahead instead.

So what you want to do is, keep the original angle of the pig (Self.Angle) and flip it (+180º).

and finally On release:

Set aiming to 0 (So it won't stay fixed on the catapult every tick)

And will move (Impulse) the object at a distance related to the distance between the PIG and the catapult

distance(Self.X, Self.Y, CatapultBlock.X, CatapultBlock.Y) / 4.5

The distance between the touch and the catapult may vary, however the distance between the pig and the catapult will never be greater than 45, so the maximum impulse you can give is 10 (45/4.5)

And this impulse will be set at the original pig's angle (Self.Angle)

While player is touching the screen the pig is MOVING at it's own angle+180, but it's original angle never changed. So you push the pig and the angle of 0+180 that will result in a movement to the left, but when you release it the pig angle will still be 0 what will result in a movement to the right.

Don't be afraid to change this values, or right click a line of code and toggle it enabled so you can see clearly what each part of your code does.

Hope this helps ^^