# How to calculate height of tower blocks? physics

0 favourites
• 7 posts
From the Asset Store
Simple yet very life-like rag doll made with Physics!
• Hi, im trying to build a game in construct where all my objects are of physics behaviour. The player will have to drop a square from the top to the ground and try to build a tower. So far ive been able to drop the square but i want to be able to know the height of the tower so far . any idea?

• You probably have a bottom sprite or platform, you need 2 events for calculating the height of your tower.

First you want to create a family for all your blocks, the first event is to check which block is the top of the tower by using the event “Pick furthest (buildingblock) from (platform)”, now you have the coordinates of the top block. Now to calculate the height of the tower you can use the expression “distance” it will ask for 4 coordinates, X and Y of the bottom point and X and Y of the top block. This returns the total distance between the 2 points and should (probably) be the towers height.

• ## Try Construct 3

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

Construct 3 users don't see these ads
• You can use an invisible helper sprite - a horizontal line. If it overlaps with a block at rest, move it up. The distance between the line and the floor is the height of your tower.

• You probably have a bottom sprite or platform, you need 2 events for calculating the height of your tower.

First you want to create a family for all your blocks, the first event is to check which block is the top of the tower by using the event “Pick furthest (buildingblock) from (platform)”, now you have the coordinates of the top block. Now to calculate the height of the tower you can use the expression “distance” it will ask for 4 coordinates, X and Y of the bottom point and X and Y of the top block. This returns the total distance between the 2 points and should (probably) be the towers height.

my event is as follows : box -> pick furthest to (line.x,line.y)

I want to be able to get the coordinates of the furthest box in the action, how do i do that?

ps: line is my platform

• An easy trick is to use For Each (ordered), and stop on the first item. This will give you the highest box. Then if you still need the height, just calculate the difference between the ground.Y and the box.Y.

I've adapted the pig-launcher template CAPX for C2 & C3 testing.

http://www.blackhornettechnologies.com/Construct2Stuff/PhysicsHeightViaSorting.capx

• > You probably have a bottom sprite or platform, you need 2 events for calculating the height of your tower.

>

> First you want to create a family for all your blocks, the first event is to check which block is the top of the tower by using the event “Pick furthest (buildingblock) from (platform)”, now you have the coordinates of the top block. Now to calculate the height of the tower you can use the expression “distance” it will ask for 4 coordinates, X and Y of the bottom point and X and Y of the top block. This returns the total distance between the 2 points and should (probably) be the towers height.

>

my event is as follows : box -> pick furthest to (line.x,line.y)

I want to be able to get the coordinates of the furthest box in the action, how do i do that?

ps: line is my platform

Event:

Box-> pick furthest to (line.X,line.Y)

Action:

Set variable Tower_Height to distance(Box.X,Box.Y,Line.X,Line.Y)

• Thank you so much for your help

>

> > You probably have a bottom sprite or platform, you need 2 events for calculating the height of your tower.

> >

> > First you want to create a family for all your blocks, the first event is to check which block is the top of the tower by using the event “Pick furthest (buildingblock) from (platform)”, now you have the coordinates of the top block. Now to calculate the height of the tower you can use the expression “distance” it will ask for 4 coordinates, X and Y of the bottom point and X and Y of the top block. This returns the total distance between the 2 points and should (probably) be the towers height.

> >

> my event is as follows : box -> pick furthest to (line.x,line.y)

> I want to be able to get the coordinates of the furthest box in the action, how do i do that?

> ps: line is my platform

>

Event:

Box-> pick furthest to (line.X,line.Y)

Action:

Set variable Tower_Height to distance(Box.X,Box.Y,Line.X,Line.Y)

• 7 posts