Altitude Calculation

Get help using Construct 2

Post » 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

Post » 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
33
G
47
Posts: 1,194
Reputation: 30,812

Post » 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

Post » 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

Post » 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

Post » Thu Feb 06, 2014 4:32 am

Take off the de, I don't think he meant to put that.
B
46
S
14
G
7
Posts: 603
Reputation: 8,096

Post » 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

Post » 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
32
S
9
G
4
Posts: 198
Reputation: 5,079


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 14 guests