Recalc X and Y

Get help using Construct 2

Post » Wed Jan 11, 2012 7:01 pm

This is a question, I am sure Yann can answer without any thought

Ok, I have two layers. The bottomm one is rotating, the overlay is not. I now want to spawn an object on the rotating layer exact underneath a certain point of the static layer.

So the question is, how can I calculate the X,Y on the rotating that matches the postion of x,y of the static layer to one certain point in time.
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Wed Jan 11, 2012 8:24 pm

Yeah layer projection is a pain

I don't use layer angle, but if the center of rotation is the center of the layout, basically the conversion is quite simple

if X and Y are the position in the unrotated layer
rX and rY the same position in the rotated layer
cX = Layoutwidth/2
cY = Layoutheight/2

you just have to take the point and counter-rotate around the center of rotation of the layer, with the same angle.
It's exactly the same formula as the other topic on planete rotating around a sun

rX = cX/2+cos(angle(cX,cY,X,Y)-LayerAngle)*distance(cX,cY,X,Y)
rY = cY/2+sin(angle(cX,cY,X,Y)-LayerAngle)*distance(cX,cY,X,Y)


Yann2012-01-11 20:25:42
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Jan 11, 2012 8:25 pm

I knew you could and would answer this. Thanks YannWeishaupt2012-01-11 20:33:48
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Wed Jan 11, 2012 8:51 pm

I guess I am doint something wrong, the calculated object are all on one line...

See my CAPX
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Wed Jan 11, 2012 9:03 pm

You might want to check this topic.
I wasn't sure at first but it sounds like the same issue.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Wed Jan 11, 2012 9:13 pm

Yeah, you could be right
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Wed Jan 11, 2012 9:17 pm

you made 2 mistakes and I made 1
Although I don't know why, I had to add the layerangle and not substract it. It doesn't make much sense to me.. but heh that works now

sniper.capx

by the way your first mistake was that you didn't copy my formula correctly (you substracted distances instead of multiply them) and the second is that you didn't calculate position on a per instance basis but in a global value and from the position of the target (thanks for translating your capx <_< I'm traumatised by german since highschool)
Last edited by Yann on Sun Sep 14, 2014 10:11 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Jan 11, 2012 9:20 pm

@Yann: You're the best! Thanks a bunch!
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Sun Jan 29, 2012 3:51 pm

Thanks @Yann

This is very useful
B
21
S
6
G
11
Posts: 30
Reputation: 5,396


Return to How do I....?

Who is online

Users browsing this forum: DemantDigitalArt, farfetchd83, mjj1990 and 5 guests