Recalc X and Y

0 favourites
  • 9 posts
  • This is a question, I am sure Yann can answer without any thought <img src="smileys/smiley2.gif" border="0" align="middle" />

    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.

  • 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)

  • I knew you could and would answer this. Thanks Yann

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

    See my CAPX

  • You might want to check this topic.

    I wasn't sure at first but it sounds like the same issue.

  • Yeah, you could be right <img src="smileys/smiley6.gif" border="0" align="middle" />

  • 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)

  • Yann: You're the best! Thanks a bunch!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks Yann

    This is very useful <img src="smileys/smiley1.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)