# Need help to interpret distance parameter setting

From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
• Hi everyone,

I am following a tutorial on physics catapult. However I need help interpreting / understanding these parameter settings. Appreciate any help. Tks.

https://43594a9df7e71904b643d4aeca25aca ... index.html

On touch of pig

Angle Parameter:

Self.Angle + 180

Distance Parameter:

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

and

On release

Impulse:

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

angle

Self.Angle

• Can you post the link to this tutorial?

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• 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 ^^

• Thank you so much!

I am still confused why there is a division of 3 below? " / 3 " What is that for?

_________________________________________

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)

the /3 is so that the distance between the slingshot and the player is divided by 3.

for instance: the distance is 100, the returned value of the distance/3 is 33, which is still less than 45

they do this so you have an extra amount of control over the projected velocity, and so the player gets pulled back slower than the user inputs...

Thank you so much!

I am still confused why there is a division of 3 below? " / 3 " What is that for?

_________________________________________

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)

• 6 posts