HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Vector towards angle

02-24-2007, 11:03 PM#1
1337D00D
I don't think I'm getting this clearly, but I want to know how to set the X and Y of a vector so that it causes movement in a certain angle when created.

I tried:

Collapse JASS:
set vex[2]=VectorCreate(GetLocationX(topos),GetLocationY(topos),5)

But it only seems to work correctly if I'm close to the center of the map.

(Anitarf's vector system)
02-24-2007, 11:21 PM#2
grim001
gah please use the vector system that's been ported to structs...

you can get it in vexorian's snow and hazards (if you fix the glitches in it)

if you want a vector from one point to another simply subtact the xs, the ys, and the zs

I think what you want is to be able to take a distance and angle and produce and x and y point...
for that just use...
newx = x + Cos(angle*bj_DEGTORAD)*distance
newy = y + Sin(angle*bj_DEGTORAD)*distance
02-24-2007, 11:43 PM#3
1337D00D
Quote:
Originally Posted by grim001
I think what you want is to be able to take a distance and angle and produce and x and y point...
for that just use...
newx = x + Cos(angle*bj_DEGTORAD)*distance
newy = y + Sin(angle*bj_DEGTORAD)*distance

That dosen't work, the unit just rockets off the map boundaries and crashes war3.
02-25-2007, 02:38 AM#4
Vexorian
Quote:
Originally Posted by grim001
gah please use the vector system that's been ported to structs...

you can get it in vexorian's snow and hazards (if you fix the glitches in it)

if you want a vector from one point to another simply subtact the xs, the ys, and the zs

I think what you want is to be able to take a distance and angle and produce and x and y point...
for that just use...
newx = x + Cos(angle*bj_DEGTORAD)*distance
newy = y + Sin(angle*bj_DEGTORAD)*distance
The glitches were fixed like a long ago.

But it doesn't really matter too much whether you use that vector system or the structs one. And the structs one is not official
02-25-2007, 08:50 AM#5
grim001
lol, its official that the structs one is less annoying to use...

and 1337d00d are you applying this movement 30 times a second? if so you need to divide the x, y, and z by 30, otherwise it's going to move super fast
02-25-2007, 12:51 PM#6
1337D00D
I tried that but it goes in a random direction depending on where I am on the map.
02-25-2007, 01:21 PM#7
Anitarf
The problem is that you only consider the "to" position, not the "from" position, so the "from" is considered as 0,0, which is the center of the map.

Collapse JASS:
set vex[2]=VectorCreate(GetLocationX(topos)-GetLocationX(frompos),GetLocationY(topos)-GetLocationY(frompos),0)

This is a correct way to get a vector between two points.
02-26-2007, 09:15 PM#8
1337D00D
Thanks, that worked.

But what if I want it to move towards a Z location as well? Using the same formula for the x and y isn't accurate enough....
02-27-2007, 11:36 AM#9
1337D00D
bump