0
101 Jan 25, 2013 at 05:14

UP, DOWN, LEFT, RIGHT.. is pretty straight forward with X/Y coordinates.. Reduce, increase them..

But what If I do not want restricted movement like that? I would like to move a spaceship into any chosen 2D direction.

On a Grid I would do something like this:

(pseudo code)

Grid_Array = [
[0,0,0],
[0,0,0],
[0,0,0]
]

If move request is “UP” {

Each Second:
player = Grid_Array[player.y - 1][player.x]

}

But How would I do this without a grid, and into every direction?

Every Second:
Move player X,Y at 360 angle.

Haeelp!
(It’s something with sin/cos isnt it?

#### 8 Replies

0
167 Jan 25, 2013 at 05:38

You want to use vectors! :) Read that blog post and the next two in the series, to get a good start.

Then, all you need to know is that the formula for a unit vector pointing in a certain direction is just (x = cos(angle), y = sin(angle))

(BTW, congrats - you’re one of today’s lucky 10,000 on vectors! Well, maybe perhaps a bit less than 10,000, since vectors probably aren’t something everyone knows by the time they’re 30…)

0
101 Jan 25, 2013 at 07:14

Cheers :)

Ironically, I have just won 10 dollars from a water bottle. There are 10.000 of those 10 dollar prizes. Awesome coincidence!

0
141 Jan 25, 2013 at 09:37

I don’t think vectors are one of those things everyone knows when they are 30.

0
101 Jan 25, 2013 at 10:42

@fireside

I don’t think vectors are one of those things everyone knows when they are 30.

Whew! Good thing that I got a few years then.

0
179 Jan 25, 2013 at 12:23

@fireside

I don’t think vectors are one of those things everyone knows when they are 30.

Exactly, some don’t even know what a vector is their entire life :D I don’t blame them though, math is difficult to communicate and I suppose you can say that it takes a while to absorb, depending how willing you are to try.

0
101 Jan 26, 2013 at 01:37

@TheNut

Exactly, some don’t even know what a vector is their entire life :D I don’t blame them though, math is difficult to communicate and I suppose you can say that it takes a while to absorb, depending how willing you are to try.

I was (am) sure he was being very sarcastic. Or at least I woulndt see why I would stumble upon vectors in my thirties. Maybe midlife crisis has to be remedied with them, who knows.
I knew a little about vectors because I do some 3D modeling, but this was unheard of :)

The article is GREAT! Very easy to understand! And very educational (I always wondered how I would do the Mario Jump!)

Thanks again
Reedbeta!

0
141 Jan 26, 2013 at 05:08

I wasn’t being sarcastic, I just think the odds that were used in the xkcd cartoon that was linked wouldn’t apply in this situation. You might be the lucky one thousand or something, since the average person doesn’t understand vectors by the time he/she reaches adulthood. At least, in my experience, I haven’t found that many that understand it unless they are into math. Anyway, the sentiment was correct. It’s always nice to learn something new.

0
101 Jan 26, 2013 at 08:14

Yes, most of the time that is nice.