• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[JASS] Coordinates X/Y question

Status
Not open for further replies.
Level 11
Joined
Sep 12, 2008
Messages
657
Hey.. im working on a missle system (curretly re-creating the current one in spell section, then im gonna update)

i set Coordinate[1] to this:
JASS:
set Coordinate[1] = GetUnitX(MissleUnit[CMTable[2]]) + MissleSpeed[CMTable[2]] * Cos (MissleFacing[CMTable[2]] * bj_DEGTORAD
and Coordinate[2] to this:
JASS:
set Coordinate[2] = GetUnitY(MissleUnit[CMTable[2]]) + MissleSpeed[CMTable[2]] * Sin (MissleFacing[CMTable[2]] * bj_DEGTORAD

(a timer that runs every 0.01 calls it)

and i set coordinates of the missle and everything works fine.

my question is:

is there a way to know how much distance it will pass in total?
(used to create a parabola formula arc system, to set the "D")
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
1) Don't use every 0.01 seconds (in JASS, I always use 0.032 seconds myself).
2) Don't use arrays for such things, just use 2 variables named x and y.

Actual question:
That depends, if you know how many time it loops: sure! Just multiply MissileSpeed[...] with the amount of time it loops and you've got the total distance.
Else, you could increase another variable by MissileSpeed[...] every time it runs, like this:

JASS:
local real angle = something // Angle to which the unit moves
local real speed = something // Speed at which the unit moves every interval
local real cdist = cdist + spd // The total distance the unit has moved
local real x = GetUnitX(u) + spd * Cos(angle * 0.017453292)
local real y = GetUnitY(u) + spd * Sin(angle * 0.017453292)
cdist would be the total distance the unit travelled up to now ("the distance it will pass in total").
If you want to set a maximum distance (the unit will stop after reaching this distance), you can set another variable ("mdist" or something) and when cdist >= mdist, then stop looping.

I use hashtables to store them myself (with the timer as the key), but you could use globals as well.
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
You should have a real global that stores the distance, like TotalDistance. The initial value should be 0.

One easy way is to assume that the missile will always move exactly MissileSpeed units. The only thing you need to do after moving the missile is
JASS:
set TotalDistance = TotalDistance + MissleSpeed[CMTable[2]]
If you want to be more careful, you could do a distance check between the old and new coordinates of the missile and add it to TotalDistance.

Edit: I'm so slow. -_-
 
Level 11
Joined
Sep 12, 2008
Messages
657
both of you,
1. inside the loop, i got this:

JASS:
                if MissleCheck[CMTable[2]] <= MissleTarget[CMTable[2]] then
                // checks how much distance the unit did untill that specific moment. if its less then max_distance, it moves the unit.
                    set MissleCheck[CMTable[2]] = MissleCheck[CMTable[2]] + MissleSpeed[CMTable[2]] // increases speed done by the missle untill now.

target = max distance

2.i use coordinate array because:
i got 8 coordinates..
1. x
2. y
3. height
4. locationz1
5. locationz2
6, 7, 8 for the parabola.

3.every 0.01 is very acurate.
i use myself speed 5 (MissleSpeed = 5), in the demo map
because 500 distance in a second is very good,
and its very acurate on speed. (it moves exactly as needed, in 1 row
instead jumping from point to point.

4.i made myself unclear.. my bad
real request is this:

get the x of the final point,
and the y of the final point.

Sorry of missunderstending.
 
Last edited:
Level 28
Joined
Jan 26, 2007
Messages
4,789
2) That's 8 out of the possible 8192 arrays you could use: still inefficient.

3) Do you really think you can see every 0.032 second? No! Of course not! The missile won't 'jump from point to point', it'll move very smoothly with 0.032!
0.01 strains the game way too much! A missile system running every 0.01 second is too cpu-consuming!
You have to reduce it...

4) Of course it's possible, it just depends how your missile system works.
Does the missile have a maximum distance it may travel?
If yes, the solution is very easy: FinalX = CurrentX + MaxDistance * Cos(angle * 0.017453292)
Same for Y (but then with the Sine).

If the systems works differently, please state that as well.
 
Level 11
Joined
Sep 12, 2008
Messages
657
it doesnt, ill reduce speed to 0.32 since i just shooted 200 missles, and game went over-lag.. (100 started having a delay)
ill test you'r theory.

edit: speed worked, and really good.. tyvm, no lags/delays either.

theory of distance: My arc theoriy failed.. and i totaly didnt understend arc system, and i readed every living tutorial.

so thank you anyways + rep (if i can, im pretty sure i allready repped you ;o)
 
Last edited:
Status
Not open for further replies.
Top