Moving a Paddle Around a Fixed Point by Degrees

Get help using Construct 2

Post » Mon Oct 01, 2012 9:03 am

Hello,

First post, been playing with Construct 2 for a short while, but have learned a ton reading through these forums. Appreciate any suggestions from you guru's out there.

Anyway, I'm toying with a game that would have a paddle that would rotate smoothly around a fixed invisible object at specific degrees like 90, 180, or 360. After doing some research, borrowing some code snippets, and attempting to brush up on my math skills I came up with the attached capx.

Its working pretty closely but I fear something is not correct in the math etc. The problem is when it hits 180 degrees and the mouse moves above the target object the paddle rotates around, the paddle jumps back to the 0 degree position. I want it to just stop at 180 degrees even if the mouse or eventually touched moved above the target object it rotates around.

I have a 90 degree setting in there as well and there is similar jumping behavior with it as well when the mouse is above the target object.

Here is the capx file.

Thanks for looking!

-AZazflyer2012-10-01 16:01:52
B
3
Posts: 6
Reputation: 487

Post » Mon Oct 01, 2012 2:40 pm

Last edited by Yann on Sun Sep 14, 2014 8:52 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Oct 01, 2012 3:54 pm

[QUOTE=Yann] https://dl.dropbox.com/u/23551572/C2/limitedAngleRange.capx[/QUOTE]

Thanks Yann. I will take a look after I upgrade to v104 this evening.

-AZ
B
3
Posts: 6
Reputation: 487

Post » Tue Oct 02, 2012 2:55 am

[QUOTE=azflyer] [QUOTE=Yann] https://dl.dropbox.com/u/23551572/C2/limitedAngleRange.capx[/QUOTE]

Thanks Yann. I will take a look after I upgrade to v104 this evening.

-AZ[/QUOTE]

Yann,

Thanks for this, it works perfectly for 180 degrees. I obviously made it way more complicated as I was working through the way the math would work on this.

So how does one change it so it can work the same but at different degrees?

Such as 90, 180 (working), and 360?

I assume targetAngle needs modification.

angle(target.X,target.Y,mouse.X,max(target.Y,mouse.Y))

I also have another idea for moving a paddle along a set of waypoints in order by waypoint UUID set in some particular shape where the paddle can move in either direction along the waypoints controlled by mouse or touch. I have not found anything like this here, but I think it could make for a neat game effect.

I have found someones [edit] Toxic's great example capx for a sprite moving along waypoints by UUID, but its not controlled by mouse or touch.

Here is the sample capx for waypoint movement. How would you integrate the movement controlled by mouse?

Thanks again Yann,

-AZazflyer2012-10-02 03:06:51
B
3
Posts: 6
Reputation: 487

Post » Tue Oct 02, 2012 8:12 am

For 360 degrees just use
angle(target.X,target.Y,mouse.X,mouse.Y)
For 90 degrees use this (modify the bold for any other range):
clamp((360+90+angle(target.X,target.Y,mouse.X,mouse.Y))%360-180,-45,45)+90
B
79
S
24
G
53
Posts: 4,735
Reputation: 40,233

Post » Tue Oct 02, 2012 8:23 am

[QUOTE=R0J0hound] For 360 degrees just use
angle(target.X,target.Y,mouse.X,mouse.Y)
For 90 degrees use this (modify the bold for any other range):
clamp((360+90+angle(target.X,target.Y,mouse.X,mouse.Y))%360-180,-45,45)+90[/QUOTE]

Thanks for the reply, I'll give it a shot.

-AZ
B
3
Posts: 6
Reputation: 487

Post » Tue Oct 02, 2012 8:45 am

R0J0hound,

Worked perfectly! And I learned about clamp today. Thanks again.

BTW, any thoughts on the moving a paddle along waypoints bidirectionally controlled by mouse or touch?

-AZ
B
3
Posts: 6
Reputation: 487

Post » Tue Oct 02, 2012 5:29 pm

How's this?
http://dl.dropbox.com/u/5426011/examples14/path.capx

Of course you could simplify it by replacing event 2 with some events that just add/subtract from sprite.dist to move left/right on the path.
B
79
S
24
G
53
Posts: 4,735
Reputation: 40,233

Post » Wed Oct 03, 2012 3:22 am

[QUOTE=R0J0hound] How's this?
http://dl.dropbox.com/u/5426011/examples14/path.capx

Of course you could simplify it by replacing event 2 with some events that just add/subtract from sprite.dist to move left/right on the path.[/QUOTE]

R0J0hound,

You are amazing with these equations and integrating them into CS. It works rather nicely. Only thing I would say (not that i'm complaining ) is how it hunts between its current path to target waypoint and the next waypoint in sequence if that makes sense.

Ideally it would not hunt like this, or even better if the paddle sprite could start to bend in the direction of the next waypoint just as it gets to the target waypoint in such a way that if 10% of the paddle sprites edge were to overlap the target waypoint, then you would see 10% of the paddle surface angle towards the next waypoint. Bending at whatever angle the next waypoint is but maintaining paddle size on either side of the waypoint as you drag in either direction.

In other words it would shrink or grow on either side of the waypoint as you drag either direction, but maintain overall size.

Don't know if that's even possible. But either way, awesome example so far and I appreciate you taking the time on it.

-AZ
B
3
Posts: 6
Reputation: 487


Return to How do I....?

Who is online

Users browsing this forum: jobel, Timedoor Indones, Yahoo [Bot] and 20 guests