Set angle towars opposite side of the screen

Get help using Construct 2

Post » Fri Feb 17, 2012 10:41 am

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.
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Fri Feb 17, 2012 11:57 am

why don't you put the hotspot of the tiledbg in the middle and just do a
set angle to floor(random(4))*90 ?
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Feb 17, 2012 1:10 pm

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.
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Fri Feb 17, 2012 2:31 pm

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
[code]+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[/code]
should work (:


Explanation:
Let's look each of these 3 actions one by one
1/ basically the first action gives you this kind of possible result:
(-1,-1)
(1,-1)
(1,1)
(-1,1)

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
(0,0)
(1,0)
(1,1)
(0,1)
you then just have to multiply these value by (layoutWidth,layoutHeight)Yann2012-02-17 14:45:58
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat Feb 18, 2012 10:39 am

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
B
29
S
9
G
6
Posts: 525
Reputation: 8,294


Return to How do I....?

Who is online

Users browsing this forum: emoticon, makkancs and 22 guests