0 Favourites

Set angle towars opposite side of the screen

  • I have this cose:

    Set position to x=choose(0,LayoutWidth) y=choose(0,LayoutHeight)

    Which positions the tiled background on one of the corners, I now need to rotate it towards the opposite angle. The hotspot is on the left-corner so:

    Position x=0,y=100 the opposite corner should be on x=100, y=0.

    To do it I did this:

    Set angle toward: x=abs(self.X-LayoutWidth) y=abs(self.Y-LayoutHeight)

    but it isn't correct because the background is now positioned diagonally, how can I fix this?

    Thanks and I hope I was able to explain myself.

  • why don't you put the hotspot of the tiledbg in the middle and just do a

    set angle to floor(random(4))*90 ?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • No because randomly putting a random angle won't fix the issue becuase since the position is also random it may not end in the right angle.. I need the hostpot in the top-left corner because I'm using sine to make it grow an reduce it for a special effect.

  • ok (:

    could help to have at least some visual to be sure but let see

    if you're on :

    • top left (0,0) angle should be 0
    • top right (layoutwidth,0) angle should be 90
    • bottom right (layoutwidth,layoutheight) angle should be 180
    • bottom left (0,layoutheight) angle should be 270

    so then hmmm I see

    +When you want
      -> tiledBg: set position to choose(-1,1),choose(-1,1)
      -> tiledBg: set angle to angle(0,0,self.X,self.Y)+135
      -> tiledBg: set position to clamp(self.X,0,1)*layoutWidth,clamp(self.Y,0,1)*layoutHeight

    should work (:


    Let's look each of these 3 actions one by one

    1/ basically the first action gives you this kind of possible result:





    2/ If you draw these points on a graph you'll notice that angles from origin to these points are multiple of 45...

    But the most important, these 4 possibilities are 90 degrees appart and in a proper order.

    So by adding 135 you end up with somthing like :

    angle(0,0,-1,-1)=-135 -> -135 + 135 = 0

    angle(0,0,1,-1)=-45   -> -45 + 135 = 90

    angle(0,0,1,1)=45    -> 45 + 135 = 180

    angle(0,0,-1,1)=135   -> 135 + 135 = 270

    3/ And then if you clamp at min 0 max 1 these kind of value you end up with





    you then just have to multiply these value by (layoutWidth,layoutHeight)

  • Thanks, I understand everything. Thanks really, there is a problem when the background goes to LayoutWidth / LayoutHeight but I'll work it out!

    Thanks truly

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