How do I create this movement

Get help using Construct 2

Post » Tue Jun 17, 2014 8:55 pm

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.

Image
B
124
S
51
G
24
Posts: 401
Reputation: 22,617

Post » Tue Jun 17, 2014 10:03 pm

B
60
S
10
G
10
Posts: 1,013
Reputation: 9,155

Post » Tue Jun 17, 2014 10:26 pm

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.
B
12
S
3
G
3
Posts: 73
Reputation: 2,647

Post » Wed Jun 18, 2014 4:58 am

@Cross_

Your explanation is very detailed but I couldn't follow it.
I was able do it on my own in a different manner.

Take a look:
Image
B
124
S
51
G
24
Posts: 401
Reputation: 22,617

Post » Wed Jun 18, 2014 7:28 pm

Nice.
One thing to keep in mind: the duration of "Every tick" can change. You should not add 1 every tick, instead you need to multiply it with dt so the object moves smoothly on slow & fast computers: "Add 100*dt to Startangle"
B
12
S
3
G
3
Posts: 73
Reputation: 2,647


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests