I am trying to make this movement but I can't figure out.

It always go to a diagonal not in a circle move.

I believe I need to use cos and sin but I don't know how.

5 posts
• Page **1** of **1**

**Posts:**1,013**Reputation:**9,165

B

60
S

10
G

10
Construct's coordinate system is a bit unusual, but you are on the right track with sin/cos.

You can use cos(angle) to get the horizontal offset and sin(angle) for the vertical offset. Put them together and you have an x,y coordinate for your sprite. Construct uses clockwise angles in degrees, so your A point is actually at 90 degrees and the B point at 180 degrees. If you set your sprite to cos(90),sin(90) it will be at the A point. Set it to cos(180), sin(180) and it will be at the B point. Note that sin/cos return values between +1 and -1. By multiplying the values you can make the circle larger or smaller: cos(90)*50, sin(90)*50 will be on a circle with radius of 50 pixels for example.

To get some movement you need to animate between those two angles over time. I.e. calculate the position for angle=90..91..92..93 and so on until you reach 180. Construct has an anglelerp function to help you with that. You would stick that inside your equation like this and update your sprite position every tick: cos(anglelerp(STARTANGLE,ENDANGLE,CURRTIME))*RADIUS, sin(anglelerp(STARTANGLE,ENDANGLE,CURRTIME))*RADIUS

The remaining task is to update the CURRTIME variable so it goes from 0 to 1 over the course of time. You can just declare a variable in the event sheet that starts out at 0 and then every tick increase it by "dt * SPEED". With SPEED=1 it would take 1 second to move from A to B. With SPEED=1/4 (that's 0.25) it would take 4 seconds to travel that distance.

You can use cos(angle) to get the horizontal offset and sin(angle) for the vertical offset. Put them together and you have an x,y coordinate for your sprite. Construct uses clockwise angles in degrees, so your A point is actually at 90 degrees and the B point at 180 degrees. If you set your sprite to cos(90),sin(90) it will be at the A point. Set it to cos(180), sin(180) and it will be at the B point. Note that sin/cos return values between +1 and -1. By multiplying the values you can make the circle larger or smaller: cos(90)*50, sin(90)*50 will be on a circle with radius of 50 pixels for example.

To get some movement you need to animate between those two angles over time. I.e. calculate the position for angle=90..91..92..93 and so on until you reach 180. Construct has an anglelerp function to help you with that. You would stick that inside your equation like this and update your sprite position every tick: cos(anglelerp(STARTANGLE,ENDANGLE,CURRTIME))*RADIUS, sin(anglelerp(STARTANGLE,ENDANGLE,CURRTIME))*RADIUS

The remaining task is to update the CURRTIME variable so it goes from 0 to 1 over the course of time. You can just declare a variable in the event sheet that starts out at 0 and then every tick increase it by "dt * SPEED". With SPEED=1 it would take 1 second to move from A to B. With SPEED=1/4 (that's 0.25) it would take 4 seconds to travel that distance.

**Posts:**73**Reputation:**2,647

B

12
S

3
G

3
5 posts
• Page **1** of **1**

## Who is online |

Users browsing this forum: No registered users and 9 guests |