move inside and on edge of circle

Get help using Construct 2

Post » Thu Sep 13, 2012 6:14 pm

I'm having some difficulties with setting this up...

I have two sprites - center (grey box) and target (red box)

target is moving with simple events using WSAD keys (no behaviors)
center is always lerping to target.XY and anglelerping to target.XY

speed of both lerps is based on distance(center.XY,target.XY)

It's fine in the way it works, but I don't like it when it comes to corners.


here distance A is always the same, so center is lerping to target with the same speed


but here distance B ? A and when target is in that area center speed's up and all other things I have looks "boosted".

My question is, how can I limit target distance to move only within green circle and only on the edge of that circle (blue stroke) using WSAD keys.
shinkan2012-09-13 18:14:57
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Thu Sep 13, 2012 6:24 pm

Would this work?

clamp(distance,0,circle radius)
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Thu Sep 13, 2012 6:30 pm

Yes and no.

I've tried that already. It's indeed making the same distance to every direction, but target movement is very rough.
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Thu Sep 13, 2012 6:35 pm

So, you want to constrain an 8-directional behavior to inside the circle? Why not have an invisible wall on the outside?
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Thu Sep 13, 2012 6:49 pm

@sqiddster check your PM ;)


think of "target" as a invisible crosshair for a "center".shinkan2012-09-13 18:51:35
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Thu Sep 13, 2012 6:57 pm

B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Thu Sep 13, 2012 7:19 pm

Yes, it's working now. I had to do some tweaks in my code to make it work.

Thanks @sqiddster for idea
Thanks @R0J0hound for example :)
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Thu Sep 13, 2012 8:02 pm

Thanks, R0j0. I would have made an example myself but I was at school ;)
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Fri Sep 28, 2012 11:07 am

Absolute GENIUS!!!!!!!
B
11
S
2
G
3
Posts: 95
Reputation: 3,028

Post » Fri Sep 28, 2012 9:13 pm

Fabulous R0J0hound
is this possible with a rounded rectangle as the limit ?kantin2012-09-28 21:14:23
B
21
S
12
G
4
Posts: 31
Reputation: 4,537

Next

Return to How do I....?

Who is online

Users browsing this forum: MarkThomas and 0 guests