Move X relative to angle of object.

Get help using Construct 2

Post » Tue Aug 01, 2017 9:47 am

Message: wad67 can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
I had previously made a post outlining the problem and the steps I had taken in order to resolve it, For some reason it has vanished.

I'm attempting to model a steam engine, for a game I am working on.

I have the relevant underlying mechanics sorted out, and I have a flywheel rotating at speeds depending on these underlying mechanics.
I'm currently unable to figure out how to implement the valve rod and piston for the engine. It does not have to do anything other than be animated in relation to the flywheel.

I currently having it travelling to the right, which is governed by the angle of the flywheel.

But I'm not sure how to get it to travel back to the left.
http://imgur.com/a/mlSDD


In addition, here is a link to the .capx
drive(dot)google(dot)com/file/d/0B_8zveWSf50XVEdOR1NXamN1WHc/view?usp=sharing
B
3
Posts: 3
Reputation: 181

Post » Tue Aug 01, 2017 5:21 pm

Is this what you're after?:

https://www.dropbox.com/s/hfifnkqcvj0yd ... .capx?dl=0

You can stop the piston tracking the angle of the flywheel by disabling the "set angle" action in both events.

In your original code the problem was that as soon as the second event moved the piston back under 600px the first event would trigger shifting it back to 250px
B
16
S
7
G
3
Posts: 395
Reputation: 3,693

Post » Wed Aug 02, 2017 1:48 am

Message: wad67 can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
mekonbekon wrote:Is this what you're after?:

https://www.dropbox.com/s/hfifnkqcvj0yd ... .capx?dl=0

You can stop the piston tracking the angle of the flywheel by disabling the "set angle" action in both events.

In your original code the problem was that as soon as the second event moved the piston back under 600px the first event would trigger shifting it back to 250px



Fantastic, thanks for the excellent example.

The code I originally had was indeed wrong, I couldn't figure out the best way to have it behave correctly.

What does the commas in the angle expression signify?

Looking at the code, without understanding the purpose of the commas, here is what I have gathered:

Every tick (and on init), the angle of the piston references the coordinates of itself and then it appears to reference an imagepoint on the flywheel.
I have also noted that the imagepoint is defined on the sprite and is easily changed, this is great although the piston seems to fall out of 'sync' at certain points of rotation.


The X coordinate also references the flywheel, by subtracting it's width from the flywheel.

So in other words, the code is dynamic and should be easily adjustable.

Thanks again, this will prove to be extremely useful for future purposes.
B
3
Posts: 3
Reputation: 181

Post » Wed Aug 02, 2017 12:21 pm

@wad67, You're welcome, although I also had the code wrong, hence the offset. What you really need is this:

https://www.dropbox.com/s/2nujpt8zcmc02 ... .capx?dl=0

I worked out the maths from this handy youtube vid:

https://www.youtube.com/watch?v=33KZXVDU4Bk

I've added the instance variables "radius" to the flywheel, and "pivotDistance" to the piston, then I calculate those lengths on start - the main reason for doing this is that the exact image-points distances are slightly less than the width ratios for those sprites. It also means we don't have to recalculate the lengths every time the positioning code block runs.

You'll notice that I've added a sprite9 in - this makes it easier for calculating the correct piston angle; you can set it invisible if you like, or you may want to change the graphics to fit with the rest of the engine.
B
16
S
7
G
3
Posts: 395
Reputation: 3,693

Post » Wed Aug 02, 2017 12:24 pm

@wad67

btw, the angle expression works as follows:

angle(x1,y,1,x2,y2)

...returns the angle between point (x1,y1) and (x2,y2)

Very handy and saves you a bunch of trig.

distance(x1,y1,x2,y2) works in a similar way
B
16
S
7
G
3
Posts: 395
Reputation: 3,693


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests