HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Velocity and Acceleration Timeout woes

07-25-2009, 12:01 PM#1
wraithseeker
When I change the timeout of the knockback for velocity and acceleration parameters, distance of knockback seems to get longer which makes the timeout unconfigurable.

Formula for distance is done by kinematics.

When a user inputs velocity and acceleration,

Here is some code simplified.

Collapse JASS:
//Initialization
//x and y are initial coordinates of target
 set d.distance = speed*speed/2/decrement
 set d.position = vector.create(x,y)
 set d.velocity = vector.create(Cos(angle),Sin(angle))
 call d.velocity.setLength(speed)   
 set d.acceleration = vector.create(d.velocity.x*-1,d.velocity.y*-1)
 call d.acceleration.setLength(decrement)

 call .velocity.velocity(.acceleration) // i know these names suck
 call .position.position(.velocity)
 call SetUnitX(.target,.position.x)
 call SetUnitY(.target,.position.y)

 
Collapse JASS:
method velocity takes vector a returns nothing
    set .x = .x + a.x
    set .y = .y + a.y
endmethod
 
method position takes vector a returns nothing
    set .x = .x + a.x * TIME
    set .y = .y + a.y * TIME
endmethod
07-25-2009, 01:15 PM#2
Opossum
Quote:
Originally Posted by wraithseeker
Collapse JASS:
method velocity takes vector a returns nothing
    set .x = .x + a.x * TIME
    set .y = .y + a.y * TIME
endmethod
 
method position takes vector a returns nothing // you should name the taken vector "v" to not mess things up
    set .x = .x + a.x * TIME
    set .y = .y + a.y * TIME
endmethod

Physics:
v = v0 + a*t
x = x0 + v*t
07-25-2009, 01:47 PM#3
wraithseeker
Is that alright? the velocity vector has not been converted to the timeframe.

I tested and it seems that it will take a long time for the unit to stop.
07-25-2009, 01:51 PM#4
moyack
v = v0 + 0.5*A*t
x = x0 + v*t

That's all.
07-25-2009, 02:11 PM#5
Opossum
Quote:
Originally Posted by moyack
v = v0 + 0.5*A*t
That's not correct. What you are thinking of is x = v0*t + 0.5*a*t² (because 0.5*a*t is the average velocity during the acceleration process).

Quote:
Originally Posted by wraithseeker
Is that alright? the velocity vector has not been converted to the timeframe.

I tested and it seems that it will take a long time for the unit to stop.
Because you didn't take time into consideration before. You're multiplying acceleration vector with TIME (which is probably 0.01 or 0.02 or something like that) now so you have to adjust all your acceleration values again by factor 100 or 50 or whatever 1/TIME is.
07-25-2009, 02:14 PM#6
wraithseeker
Finding time is sort of impossible.

For example 800 initial velocity and -7 acceleration

T = -vi/a
800/-7 = 114.28........
07-25-2009, 02:31 PM#7
Opossum
Uh what? You don't have to find time.
You just need to use bigger (or if negative smaller) values for acceleration.

Example:
• using the function you posted in the first post
let's say you have a unit with an initial velocity v of 1000 and a constant negative acceleration (air resistance or whatever) of -10. Each time your method "velocity" is called that acceleration will be added to velocity, so it will take 100 function calls to make that unit stop IRREGARDLESS of how big TIME is. That means if TIME is 0.01 then it will take exactly 1 second to make the unit stop. But if you increase that value to 0.02 it will take 2 seconds which shouldn't be the case.

• using the correct function (same values as first example):
Now it will take 10000 function calls to make the unit stop because TIME (= 0.01) is taken into consideration. But as that function is called every TIME seconds (I assume?) it will take a constant amount of time (= 100 seconds) to stop the unit irregardles of TIME. But as the time it takes to stop the unit is 100 times as big now you have to multiply the initial acceleration by factor 0.01.
07-25-2009, 02:40 PM#8
wraithseeker
Yes it does works, now thanks alot but I want to ask about something.

when
Collapse JASS:
method velocity takes vector a returns nothing
    set .x = .x + a.x * TIME // why do you multiply acceleration by the time period and not velocity too
    set .y = .y + a.y * TIME
endmethod
 
method position takes vector a returns nothing // you should name the taken vector "v" to not mess things up
    set .x = .x + a.x * TIME
    set .y = .y + a.y * TIME
endmethod
07-25-2009, 02:43 PM#9
Opossum
Because nature says:
v = v0 + a*t
x = x0 + v*t
And you don't want to argue with nature do you? I'm sure you will lose.
07-25-2009, 08:02 PM#10
Pyrogasm
...the reason you're multiplying by time is because the input is in WC3 Units per second, and you're moving stuff on a timestep. So your Velocity must then be converted to "Wc3 Units per TIME".