0 Favourites

# 2d planet game help

This forum is currently in read-only mode.
• 5 posts
• In the custom movement behavior you can move objects "horizontally" and "vertically" according to a specified angle of orientation. I thought, "this will be perfect for my 2d planet game where there is no 'up' or 'down'-- its all relative! I now realize this might be more math than I anticipated.

Is there a way to get this relative "horizontal" and "vertical" speed of an object, and not just it's X and Y speed?

Better yet, can someone take a look at this cap and tell me if there is a better way to do this? In addition to this road block I have hit, there are numerous other little flaws in my custom movement platform behavior. I feel there is some sort of elegant trigonometric solution to all my problems that I am unable to see...

http://dl.dropbox.com/u/19590484/compass.cap

• Maybe I am misunderstanding this. but "horizontal" and "vertical" relative to the angle of motion doesn't make much sense.

When your object moves with 50 pixel per second at an angle of 10�, then the speed's x-component is cos(10) * 50 (ca 49.24), and the y-component is sin(10) * 50 (ca 8.68)

But a relative "vertical" component to an object moving at any angle would just be the speed (cos(0)) and the "horizontal" one would always be 0 (sin(90))

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

Construct 3 users don't see these ads
• My apologies, I meant angle of the sprite and not the angle of motion.

At any rate, even with you misunderstanding what I meant you still answered my question for a trigonometric solution to calculating X and Y. I am still trying to understand where these triangles are being formed.

Thank you so much!

• I am still trying to understand where these triangles are being formed.

object starting point is red

object ending point is pink

light grey lines are examples of nonrelative x and y offsets.

black are examples of directions of motion.

when you're trying to get the speed relative to an angle, you're trying to get the black part of the triangles.

<img src="http://dl.dropbox.com/u/1013446/spriterspam/xyrel.png" border="0" />

• My apologies, I meant angle of the sprite and not the angle of motion.

Ah, yes, that makes sense. And lucid's graphic should make it more clear.

But here is a practical example:

Again, the sprite is moving with 50 pixel per second at an angle of 10?

x-component 49.24

y-component 8.68

Now the sprite rotates to 330?. The player hits the thrust button (max speed again 50 pps)[or a planet gets into the influence of another mass, something like that]. Now you need to aim for a final

x-component cos(330) * 50 -> ca 43,3

y-component sin(330) * 50 -> -25

So you need to interpolate (qarp should do) between

x 49.24 and 43,3

y 8.68 and -25

for whatever time feels right for your game.

• 5 posts