Get help using Construct 2

### » Mon Jan 26, 2015 2:18 pm

This already puts the arrow always halfway between the player and it's target, rotating towards it.

Its not complicated math, just a bit of XY-Coordinates adding subtracting... easy, but as you can see, very effective. And saves you a lot of performance
You do not have the required permissions to view the files attached to this post.
B
8
S
3
Posts: 197
Reputation: 1,207

### » Mon Jan 26, 2015 5:34 pm

MultipleChoice wrote:> @SecondDimension , @80bit

This is a simple way to do it.

DON'T rotate the layer, on which the player or Arrow or whatever is this way, since the rotation is not centered. It confuses the coordinates.
Rather rotate everything around the player in the center of the map.

You can also let the arrow easily disappear, if target "is on-screen", or when the distance (rather of the XY coordinates, as done in the file, not the function dist(), as this would detect a circle, but you have a square Screen) of the halfway point being smaller than your View-Port-edges.

Hope it helps...

Hey man, thanks so much for your time on this - Unfortunately rotating the layer is something I have to do. 14 months of development already built around the layers rotating, it would be too time consuming to switch it so everything rotates around the player.

Also, in regards to the code above, its nice for sure, i like how it smoothly transitions from the object to the screen edge, but yeah without the rotation i just cant use it.

i was trying to account for the rotation using transform/rotate trigonometry functions but i barely knew what I was doing, so it ended up messed up.

p = ViewportRight/2
q = ViewportBottom/2

(so now p,q is the exact centrepoint of the viewport)

newx=(x−p)*cos(θ)−(y−q)*sin(θ)+p
newy=(x−p)*sin(θ)+(y−q)*cos(θ)+q
Made Friday the 13th: Killer Puzzle - www.f13killerpuzzle.com
B
29
S
9
G
4
Posts: 387
Reputation: 5,676

### » Mon Jan 26, 2015 7:01 pm

> @SecondDimension , @80bit

The map rotation problem was something I realized at the end, so I cheated deleting that possibility
(Since I had two separate layers apparently that is, and I did not have time to realize that.)
Now I had time to take a look again, and I revise!!

IT DOES WORK WITH ROTATION, but all objects obviously have to be on that layer (which you want to rotate).
You do not have the required permissions to view the files attached to this post.
B
8
S
3
Posts: 197
Reputation: 1,207

### » Mon Jan 26, 2015 7:07 pm

> @80bit

p = ViewportRight/2
q = ViewportBottom/2

(so now p,q is the exact centrepoint of the viewport)

There is a mistake, Viewport gives you the COORDINATES, not the window size. Confusion! Take care, you have to use either WindowHeight/Width for that, or just use Player.X Player.Y, since he is centered! Or (ViewportBottom-ViewportTop)/2 to subtract the coordinates, and get half of the screen size. I hope you understand.

That is, why you have to tell him, which layers coordinates to get by VieportBottom(Player.LayerNumber) or just ViewportBottom(0).

When you work with stuff like that, it is a helpful thing to display those variables on your screen (set Text = ViewportLeft ), to avoid such confusions. Also there you get a good idea, how they relate, and how you can use that to determine the formula.
B
8
S
3
Posts: 197
Reputation: 1,207

### » Mon Jan 26, 2015 7:29 pm

MultipleChoice wrote:> @SecondDimension , @80bit

The map rotation problem was something I realized at the end, so I cheated deleting that possibility
(Since I had two separate layers apparently that is, and I did not have time to realize that.)
Now I had time to take a look again, and I revise!!

IT DOES WORK WITH ROTATION, but all objects obviously have to be on that layer (which you want to rotate).

Well it works with rotation, but it has the same issue as my original version: when the screen is rotated, the arrow does not stay visible when you get too far from the Target... the arrow moves outside of the visible area unless you are actually near the target / the target is on-screen.
Made Friday the 13th: Killer Puzzle - www.f13killerpuzzle.com
B
29
S
9
G
4
Posts: 387
Reputation: 5,676

### » Mon Jan 26, 2015 7:30 pm

Here's the LayerToCanvas/CanvasToLayer approach if you want to see that.
You do not have the required permissions to view the files attached to this post.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,850

### » Mon Jan 26, 2015 7:36 pm

@MultipleChoice

Please see this movie for what my actual problem is: http://d.pr/v/1b0eN/4oqF4TZm
Made Friday the 13th: Killer Puzzle - www.f13killerpuzzle.com
B
29
S
9
G
4
Posts: 387
Reputation: 5,676

### » Mon Jan 26, 2015 7:38 pm

ramones wrote:Here's the LayerToCanvas/CanvasToLayer approach if you want to see that.

you, my friend are royalty among humans. thank you so much for the help this is exactly what I needed!!!!!
Made Friday the 13th: Killer Puzzle - www.f13killerpuzzle.com
B
29
S
9
G
4
Posts: 387
Reputation: 5,676

### » Mon Jan 26, 2015 7:54 pm

> @80bit : S**t, you are right, it does break, when you rotate
I am not sure, but did you realize, when you rotate your layer, the movement also get confused... You will have several problems.

I am quite sure, you can solve the rotation different also.
B
8
S
3
Posts: 197
Reputation: 1,207

### » Mon Jan 26, 2015 8:15 pm

ramones wrote:Here's the LayerToCanvas/CanvasToLayer approach if you want to see that.

Awesomely short. Did not know this CanvasToLayer stuff either. Thanks.
B
8
S
3
Posts: 197
Reputation: 1,207

PreviousNext