Set Position vs Move At Angle

» Mon May 25, 2009 1:30 am

Oh comon Sol, it's just sin and cos, they're a game designers two best friends. Get more acquainted with them!
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

» Mon May 25, 2009 2:15 am

Sin and cos are rife through game design even if you don't use them in events(they're peppered through almost all the behaviors and rendering engine). It can only do you good to learn a little of the maths behind game design!
Scirra Founder
B
355
S
208
G
71
Posts: 22,822
Reputation: 176,608

» Mon May 25, 2009 4:17 am

[quote="QuaziGNRLnose":p1x8gfp6]
im doing this without variables to store the relative angle and distance cause i don't feel like it.
point.x+cos(angle(point.x,point.y,object.x,object.y)+(amount you want changed))*(distance(point.x,point.y,object.x,object.y))
point.y+sin(angle(point.x,point.y,object.x,object.y)+(amount you want changed))*(distance(point.x,point.y,object.x,object.y))[/quote:p1x8gfp6]

[quote="Mipey":p1x8gfp6]Move at angle is fine, too. It is basically like this:
x = x + cos(angle)*distance
y = y + sin(angle)*distance[/quote:p1x8gfp6]

Its just that it strikes me as odd having a shortcut for the smaller latter and not the longer former.
Can live without it though. It's just odd.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

» Mon May 25, 2009 8:18 am

To rotate around a point, you just draw a circle around that...

Moon.X = Earth.X + cos(period) * distance
Moon.Y = Earth.Y + sin(period) * distance

To control the speed, just control the period yourself; basically it is angle from 0 to 360, the rendering speed depends on by how much you increment the period. So, just increment the period with time delta, don't forget to subtract 360 whenever it gets over 360. It is neater that way.

period=period+rotationspeed*timedelta
period > 360 ; period = period - 360
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Previous