How do I create this movement

0 favourites
  • 5 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Check this post :

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

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

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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)