| 07-02-2009, 10:41 AM | #1 |
So I have vector A which is x y z of initial unit position available and vector B x y z of final unit position available, how do I move them? |
| 07-02-2009, 10:53 AM | #2 |
how about SetUnitX/Y? and for Z the usual flying height trick.. |
| 07-02-2009, 11:02 AM | #3 |
The problem is how to do the calculations, not the function calls. |
| 07-02-2009, 11:43 AM | #4 |
parametric functions for each of the XYZ components respect time. |
| 07-02-2009, 11:50 AM | #5 |
JASS:// initial vector set d.zx = GetUnitX(target) * Cos(angle) set d.zy = GetUnitY(target) * Sin(angle) call MoveLocation(L,d.x,d.y) set d.zz = GetLocationZ(L) // I am not using Z axis for now, ignore it same for the rest JASS:// speed vector set d.x = speed * Cos(angle) * TIME set d.y = speed * Sin(angle) * TIME set d.z = 0 * TIME JASS://decrement vector set d.dx = decrement * Cos(angle) * TIME set d.dy = decrement * Sin(angle) * TIME set d.z = 0 * TIME I am new to vectors so don't blame me for doing stupid stuff, this is deacclerating and not accelerating. They start from a variable of x speed and then x decrement and end at 0 speed. JASS:// calculations set d.x = d.x - d.dx set d.y = d.y - d.dy set d.zx = d.zx - d.x set d.zy = d.zy - d.y call SetUnitPosition(d.target,d.zx,d.zy) Am I doing any of the calculations wrongly? I sort of followed anitarf's vector system test map example. EDIT: What is a parametrix function? |
| 07-02-2009, 12:25 PM | #6 |
Parametric functions: http://en.wikipedia.org/wiki/Parametric_equation |
| 07-02-2009, 12:31 PM | #7 |
I don't understand it very well, could you explain more? EDIT: I did something like this now JASS:set d.x = speed * Cos(angle) * TIME set d.y = speed * Sin(angle) * TIME set d.z = 0 * TIME JASS:set d.x = d.x - d.dx set d.y = d.y - d.dy call SetUnitPosition(d.target,GetUnitX(d.target)+d.x,GetUnitY(d.target)+d.y) Am I correct? |
| 07-02-2009, 01:21 PM | #8 |
parametric functions is represent how change XYZ corrdinates respect a parameter (in this case, time). So movement in X,Y,Z are expressed sa independent functions respect time. X(t) = a function Y(t) = another function Z(t) = another function Parabolic movement is a good example, a parabola can be expressed in parametric functions in this way: X(t) = X0+Vx*t Y(t) = Y0+Vy*t+0.5gt^2 So in your examples, yes, you're doing it in a parametric way. |
| 07-02-2009, 01:25 PM | #9 |
+0.5gt^2 Can be skipped right?' So in your examples, yes, you're doing it in a parametric way. The second example? |
| 07-02-2009, 01:33 PM | #10 |
JASS:set v=vector.difference(B,A) //get the difference between the start and the end point call v.scale(TIME/(v.getLength/speed)) //get the velocity that matches the desired speed //...then, in a function run by a periodic timer call position.add(v) call SetUnitX(u, position.x) call SetUnitY(u, position.y) call MoveLocation(l, position.x, position.y) call SetUnitFlyHeight(u, position.z-GetLocationZ(l), 0) |
| 07-02-2009, 01:43 PM | #11 | ||
Quote:
Quote:
|
| 07-02-2009, 02:13 PM | #12 | ||
@Anitarf
Didn't work for me. How would I use that one vector to make it slow down?
@Moyack Everything works good except when I add in * TIME in the periodic function. JASS:
set d.zx = speed * Cos(angle) * TIME
set d.zy = speed * Sin(angle) * TIME
set d.zz = 0 * TIME
set d.dx = decrement * Cos(angle) * TIME
set d.dy = decrement * Sin(angle) * TIME
set d.zz = 0 * TIME
// periodic function
set d.zx = d.zx - d.dx // when I put * time for both of this, they bug I guess it is already because I converted it to a timeframe?
set d.zy = d.zy - d.dySo which method should I use which is more user friendly? |
| 07-02-2009, 02:39 PM | #13 |
I'm sorry, I don't really understand your code. Perhaps post a more detailed description of what you're trying to do? |
| 07-02-2009, 02:40 PM | #14 |
Updated the post. EDIT: The second approach works but I am not supposed to be getting knocked back at a constant speed but speed is constantly getting reduced y a decrement. |
| 07-02-2009, 03:26 PM | #15 |
Well, you don't really need to use a 3D vector library for simple 2D knockback. Also, looking at your code it seems you want to move your unit for a certain distance, not from point A to B (sure, one can be translated into the other, but it's pointless if the code then has to translate it back). Anyway, there are knockback systems out there that do all this stuff for you. |
