# Moving a Paddle Around a Fixed Point by Degrees

0 favourites
• 9 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
• 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! <img src="smileys/smiley1.gif" border="0" align="middle">

-AZ

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• https://dl.dropbox.com/u/23551572/C2/limitedAngleRange.capx

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

-AZ

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

-AZ

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  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,

-AZ

• 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

• 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

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

-AZ

• 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

• 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.

• 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.

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 <img src="smileys/smiley2.gif" border="0" align="middle">) 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

• 9 posts