Maths Help Please

Get help using Construct 2

Post » Sun Jun 30, 2013 8:18 pm

Hi everyone, I have a maths problem that I'm struggling with, and I was hoping someone could help.
I'm doing a top-down game, and I would like an arrow to point to the next objective if that objective is off-screen. I have set this up no problem - when the objective item is not on screen then I am:
* setting the arrow's poition to the the player's poition,
* setting the arrow's angle towards the objective,
* moving the arrow 200 pixels forward at its current angle.

This works OK, but rather than move the arrow 200 pixels, ideally I would like to figure out the distance between the arrow and the edge of the screen, and move it forward by that number of pixels. That way the arrow would stick to the edge of the screen, if you see what I mean.

So I know the X & Y of the viewport, and the angle the arrow is pointing, but can't get the next step. I'm sure there's some trigonometry that could help me here, but I'm struggling. Any ideas? Thanks
B
15
S
5
Posts: 141
Reputation: 1,657

Post » Sun Jun 30, 2013 11:04 pm

@SecondDimension

Here is an example. Its not mine just one i picked up on the forums some time ago.

Arrow Pointer

hope it helps
B
47
S
16
G
9
Posts: 1,097
Reputation: 11,180

Post » Mon Jul 01, 2013 12:08 am

Great, yes it does help! I'd tried a heavy-handed method similar to that, but I wasn't using a variable as a distance buffer; this way is definitely cleaner. Thanks
B
15
S
5
Posts: 141
Reputation: 1,657

Post » Sat Jan 24, 2015 4:43 am

@spongehammer

Any chance you still have this example handy? Im trying to do something similar but for an enemy marker. I can get it working no problem as long as my layout isnt rotating, just using clamping to the viewport, but as soon as my layer rotates, the X,Y gets all bungled with the rotation so its no longer accurate. Just curious if this example tackled rotation or how i might be able to do that?

Huge love...
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
25
S
7
G
3
Posts: 375
Reputation: 4,852

Post » Sat Jan 24, 2015 5:18 am

Oh, and @SecondDimension
:)
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
25
S
7
G
3
Posts: 375
Reputation: 4,852

Post » Sat Jan 24, 2015 10:00 am

@80bit

I think this is the one i posted..
You do not have the required permissions to view the files attached to this post.
B
47
S
16
G
9
Posts: 1,097
Reputation: 11,180

Post » Sat Jan 24, 2015 8:28 pm

@spongehammer

Thank you so much - can you check this updated CAPX?

Basically if you use the A & D keys, it rotates the layer by 15 degrees each way so you can see how the indicator no longer lines up to the edge of the layout. Im trying to account for the rotation of the layout and reposition it according to where it should be with the angle change, but i cant seem to figure it out properly...

Do you have any ideas? Thank you a million times over for checking it out..
You do not have the required permissions to view the files attached to this post.
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
25
S
7
G
3
Posts: 375
Reputation: 4,852

Post » Sun Jan 25, 2015 6:44 pm

@80bit

It might be a while before i can take a look as i am away at the moment and cant access C2. You might want to look at the CanvasToLayer expressions to convert the co-ordinates as the layer is rotated.

https://www.scirra.com/manual/126/system-expressions
B
47
S
16
G
9
Posts: 1,097
Reputation: 11,180

Post » Mon Jan 26, 2015 9:30 am

@spongehammer - Yea been messing with this trying to get it working but cant quite seem to wrap my head around the context. eg. am i clamping the arrows first, then translating it to canvas then dropping it back down on, eg .the hud layer? just cant seem to understand what i need to do exactly haha :)

Also worried about performance of doing that layer/canvas translating as someone mentioned it slowed things down for them, but i will probably only have about 20-50 objects on the screen max that are being positioned in this way..
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
25
S
7
G
3
Posts: 375
Reputation: 4,852

Post » Mon Jan 26, 2015 2:12 pm

> @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...
You do not have the required permissions to view the files attached to this post.
B
8
S
3
Posts: 197
Reputation: 1,207

Next

Return to How do I....?

Who is online

Users browsing this forum: alajajm, LaurenceBedford, pokka, robopunch and 13 guests