# Altitude Calculation

Get help using Construct 2

### » Wed Feb 05, 2014 9:43 pm

I'm making a puzzle game where the player manipulates a see-saw to fling an object into a goal.

I would like to have an on-screen altitude readout showing a constant readout of the object's current altitude.

How should I write the event to calculate this?
B
11
S
3
Posts: 30
Reputation: 745

### » Wed Feb 05, 2014 10:19 pm

are you throwing the object with physics ? If so then I think it would just be a case of

every tick     text:set text object.Y

-----

or are you trying to calculate the position with gravity and mass and velocity... ?

example

edit - altered capx so displaying height only while object is moving. (is physics sleeping/else)RamPackWobble2014-02-06 11:03:00
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,912

### » Wed Feb 05, 2014 10:22 pm

Create a variable StartY and on start of layout set it to object.y
Create a variable Altitude and every tick set it to round(abs(object.y-StartY))

Edit: Removed "de" (stupid swype keyboard!)LittleStain2014-02-06 08:38:20
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Wed Feb 05, 2014 11:06 pm

I will try both those options - thank you very much!

The calculation just needs to be a simple arbitrary number: X meters off the ground.
B
11
S
3
Posts: 30
Reputation: 745

### » Wed Feb 05, 2014 11:28 pm

[QUOTE=LittleStain]
Create a variable Altitude and every tick set it to round(abs(object.y-StartY))de[/QUOTE]

What does the "de" do? Construct 2 is throwing and error when I type that in.
B
11
S
3
Posts: 30
Reputation: 745

### » Thu Feb 06, 2014 4:32 am

Take off the de, I don't think he meant to put that.
B
48
S
15
G
8
Posts: 603
Reputation: 8,776

### » Thu Feb 06, 2014 7:32 am

It was my tablet-keyboard acting funny..
Sorry..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Thu Feb 06, 2014 8:30 am

A simpler option without variables might be to just take the Y value of your ground level and set your text to the difference between that and the object's Y value. So just something like Set Text to GroundY - ObjectY. Or if you want it always relative to the catapult, use catapult.Y instead of ground.Ahr Ech2014-02-06 08:36:37
B
38
S
10
G
4
Posts: 203
Reputation: 5,361