Math - Picking specific points

Get help using Construct 2

Post » Mon Sep 07, 2015 10:41 am

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?
B
7
S
2
Posts: 92
Reputation: 663

Post » Mon Sep 07, 2015 1:15 pm

Maybe you can use the angle function ?

like "move 100px at angle(origin.X,origin.Y,target.X,target.Y) ?
B
8
S
4
Posts: 131
Reputation: 1,205

Post » Mon Sep 07, 2015 1:46 pm

@JeremyBenson

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
B
24
S
3
G
1
Posts: 451
Reputation: 2,165

Post » Mon Sep 07, 2015 2:22 pm

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..
B
7
S
2
Posts: 92
Reputation: 663

Post » Mon Sep 07, 2015 3:07 pm

looks familiar :)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,882


Return to How do I....?

Who is online

Users browsing this forum: MiloMasson, Yahoo [Bot] and 31 guests