Math - Picking specific points

0 favourites
  • 5 posts
From the Asset Store
Aliens are invading our planet! Solve the math question, and attack the alien with your laser. Covers addition, subtract
  • I'm just curious if someone could take the time to teach me a little math. I'm wondering what the best way is to pick a point from the sprite in any direction, a number of pixels away.

    I would think the best way would be by degree, but not sure how to do it. Like say I wanted to move the sprite 100px backwards, that would be 100 pixels at 180 degrees.

    Picture a sprite on the canvas, this has rays going in every direction that fits.. so how do I say, move 100px along this ray... or that ray? How do I get the x,y for that point?

  • Maybe you can use the angle function ?

    like "move 100px at angle(origin.X,origin.Y,target.X,target.Y) ?

  • What you describe are polar coordinates. That are an angle and a radius r.

    You can convert from polar to cartesian coordinates (the normal xy-coordinate system) with

    x= r * cos(angle)

    y= r * sin(angle)

    Then you have to add this to your x and y sprite position.

    your example r=10 angle=180°

    x = 100 * cos(180°) = 100 * -1 =-100

    y= 100 * sin(180°) = 100 *0 = 0

    add this to your sprite position xy an you have your new point.

    Look wiki for more Information

    https://en.wikipedia.org/wiki/Polar_coordinate_system

  • Cool, thanks to both I finally have all the math needed for basic movement.

    Discovered how to move an object a number of px in any direction..

    How to move object up to a certain random number of px from itself..

    Now I just need to figure out custom movements, like following an arc, or what have you.. Have no idea where to start with that..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • looks familiar

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