Speed of the knockback is <= 0

by wraithseeker
Tags: knockback, speed
 P: 29 I can explain them by 2 ways, I am making some sort of a game. I am doing a some sort of a knockback but the unit will be flying. Imagine that the knockback ends only when the speed of the knockback is <= 0 and there is decrement & speed which is user specified. The unit is moved by a timeframe of 0.03 seconds and gravity = -981. I know it is initially 9.81 but in the game it is calculated as -981. Every 0.03 seconds untill speed <= 0, speed is constantly reduced by decrement and how would I go about making the unit perform a parabola from point A (initial position of the unit) to point B(final area). I do not really know how to calculate distance with speed and decrement but is it like -1 * speed * speed / (2 * -decrement / Timeframe) And I want to know how can I get the time of the knockback. ??? In another way I could say it like unit A has 3 vectors. Vector position, acceleration and velocity(They get updated every timeframe). Position stores the position of the unit and acceleration is actually deacceleration as it is negative. Velocity is just initial speed of the unit and gets decreased every timeframe by acceleration. Velocity vector adds the acceleration and then Position vector adds the velocity every timeframe. The knockback would end when the dotproduct of velocity and acceleration >= 0. Distance used to calculate is the same as the following one above. So How would I go about doing a perfect parabola?
 Mentor P: 11,862 This is possibly a stupid question, but... what is a "knockback"?
HW Helper
P: 7,170
 knockback?
I assume this is like an angled trampoline for a ball. The USA name for this is a pitchback:

http://www.sportsworldwholesalers.com/2770fs.html

 Quote by wraithseeker So How would I go about doing a perfect parabola?
Using parametric equations:

Position:

Px(t) = Vx t + Px0
Py(t) = 1/2 Ay t2 + Vy0 t + Py0

Velocities:

Vx(t) = Vx
Vy(t) = Ay t + Vy0

Accelerations:

Ax(t) = 0
Ay(t) = -981

In the classical numerical integration case, you only know the equations for acceleration for a given set of velocities and positions, but this is a case where the equations for velocities and position are also known.

The acceleration equations, combined with initial velocities and positions, are what you need to create a parbola using numerical integration. Since the integrals of acceleration and velocities are known equations, you can use these to confirm your method of numerical integration

In cases like this one, where acceleration is constant or can be calculated based on time without knowing velocities or position, an averaging method can be used if the steps are small enough:

Vn+1 = Vn + 1/2 (An+An+1) Δ t

In this case, since acceleration is a constant, you just end up with the known equations for velocities. Position calculations become:

Pn+1 = Pn + 1/2 (Vn+Vn+1) Δ t

Again, because acceleration is a constant, position calculations will also end up as the known equations for positions. Post #8 shows this for Py.

Numerical_intergration_wiki.htm

Predictor-corrector_wiki.htm

Runge_Kutta_wiki.htm

A more classic example of numerical intergration produces a sine or cosine wave using:

A = -P

Along with initial velocity V0 and position P0.

 P: 29 Speed of the knockback is <= 0 is T time or is T timeframe? initial position z = the height of the object initial acceleration = -981/2 in the timeframe function itself (TIME = TIMEFRAME) velocity.z = GRAVITY + (TIME*TIME) + acceleration.z* TIME position.z = position.z + velocity.z
HW Helper
P: 7,170
 Quote by wraithseeker is T time or is T timeframe?
T is elapsed time, Δt is time step. I don't know what you mean by time frame.
 P: 29 I'm doing some sort of programming and I have to move a object by a timeframe which lets say is 0.03. velocity.z = velocity.z + acceleration.z * (timeperiod*timeperiod) position.z = position.z + velocity.z * timeframe timeperiod = timeperiod + timeframe Here are my current calculations, are they correct? I don't know why did you multiply initial velocity by the timeperiod.
HW Helper
P: 7,170
 Quote by wraithseeker I'm doing some sort of programming and I have to move a object by a timeframe which lets say is 0.03. velocity.z = velocity.z + acceleration.z * (timeperiod*timeperiod) position.z = position.z + velocity.z * timeframe timeperiod = timeperiod + timeframe Here are my current calculations, are they correct?
first one should be:

velocity.z = velocity.z + acceleration.z * (timeperiod)

 I don't know why did you multiply initial velocity by the timeperiod.
That's part of the formula for position. (note - I editted my previous post to clean up the names in the formulas.)

If acceleration is constant:

Δt = t1 - t0

initial velocity = Vy0
final velocity = Vy1= Vy0 + Ay Δt
average velocity = 1/2 (Vy0 + Vy1) = 1/2 (Vy0 + (Vy0 + Ay Δt)) = Vy0 + 1/2 Ay Δt

initial position = Py0
final position = Py0 + (average velocity) Δt = Py0 + (Vy0 + 1/2 Ay Δt) Δt = Py0 + Vy0 Δt + 1/2 Ay Δt2
 P: 29 I don't really get some parts understood but I think I got some part of it right. Object A velocity = vx,vy,vz (any numbers will do) acceleration = ax,ay,az ( any number will do except az which is gravity*0.5 like you said) distance = the distance covered by the ball time = distance/(speed/2) (Finding the distance covered by the ball when thrown) Position vector is available but not random numbers. Current calculations in the timeframe are as followed vx = vx + ax vy= vy + ay vz = vz + az * timeframe px = px + vx * timeframe py = py + vy * timeframe pz = pz + vz * timeframe If you do not know what the variables mean, they are; velocity vector = vx,vy,vz position vector = px,py,pz acceleration vector = ax,ay,az. Final velocity are all 0. I don't understand much of why are you using average velocity so I posted this. To sum it up, how would I do a parabola if velocity z can be inputted by any number? Setting it higher or lower makes it look stupid.
HW Helper
P: 7,170
 Quote by wraithseeker I don't understand much of why are you using average velocity.
Say a vehicle is experiencing constant acceleration. At time t0 the vehicle is moving at 30 kph, one second later, at time t1, the vehicle is moving at 50kph. How much distance (position) the vehicle travel during this time?

To solve this type of problem you use distance = average velocity x time.

For numerical integration, one simple method is to use linear interpolation for each interval, change in position = "average" velocity x time step, this the equivalent of "trapezoidal" rule (for finding area under a curve).
P: 29
Do I do them for the x y z coordinates or just the z coordinates?

Which should I use?

 Say a vehicle is experiencing constant acceleration. At time t0 the vehicle is moving at 30 kph, one second later, at time t1, the vehicle is moving at 50kph. How much distance (position) the vehicle travel during this time? To solve this type of problem you use distance = average velocity x time.
Or

 For numerical integration, one simple method is to use linear interpolation for each interval, change in position = "average" velocity x time step, this the equivalent of "trapezoidal" rule (for finding area under a curve).
I am abit confused by those 2 statements.
HW Helper
P: 7,170
 Quote by wraithseeker Do I do them for the x y z coordinates or just the z coordinates?
You can do them for all coordinates, but velocity only changes where there is acceleration, and in your example acceleration only occurs on the z axis. Calculating the average velocity when it's not changing still works. If the velocity is 30kph at the start and 30kph at the end, than average velocity = 1/2 (30 + 30) = 30, so might as well be consistent and use the same method for x, y, and z, while noting that acceleration only occurs on the z axis.

 Quote by Jeff Reid Say a vehicle is experiencing constant acceleration. At time t0 the vehicle is moving at 30 kph, one second later, at time t1, the vehicle is moving at 50kph. How much distance (position) the vehicle travel during this time? To solve this type of problem you use distance = average velocity x time.
 confused
The initial speed of the vehicle is 30 kph, the final speed is 50 kph, the average speed = 1/2 (30 + 50) = 40 kph.

 For numerical integration, one simple method is to use linear interpolation for each interval, change in position = "average" velocity x time step, this the equivalent of "trapezoidal" rule (for finding area under a curve).
 confused
http://en.wikipedia.org/wiki/Trapezoidal_rule

In your case, we can calculate velocity based on elapsed time, so given Vz0, Vz1 can be calculated via Vz1 = Vz0 Az x Δt. The "a" used in the wiki article would be Vz0, and the "b" would be Vz1.

Note that this type of numerical integration only works when acceleration is function of time. If acceleration is a function of velocity and position, then standard numerical integration methods are required. For a simplified aerodyamic drag equation, A = -V2 is a better example, although it's simple enough to integrate directly. I already mentioned A = -P which generates a sine wave as another example.
 HW Helper P: 7,170 Here is an example of a crude "predictor corrector" algorithm. To simplify things, I'll use an example that where only one level of integration is required, such as A = -c V2 where c is some constant. Initial state V0 Time step = Δt A0 = -c V02 Make first guess assuming A is constant: Ag 1 = A0 Calculate a velocity guess based on average acceleration Vg 1 = V0 + 1/2 (A0 + Ag 1) Δt Make a new guess for A based on Vg1 Ag 2 = A(Vg 1) = -c Vg 12 Calculate another velocity guess based on average acceleration Vg 2 = V0 + 1/2 (A0 + Ag 2) Δt If Δt is small enough that an inflection point isn't an issue, this process will converge, so repeat this process: Ag n+1 = A(Vg n) Vg n+1 = V0 + 1/2 (A0 + Ag n+1) Δt Until | Ag n+1 - Ag n | < some tolerance factor. You can put a limit on this, if | Ag n+1 - Ag n | is not less than the tolerance factor after some specific number of steps, say 16, then decrease Δt and repeat the step. If convergence occurs in less than say 4 steps, increase Δt. Then you start a new step using A1 = Ag n+1 V1 = Vg n+1 This is a crude process but most of the methods require generating a few initial steps before the iteration (looping) process can be eliminated. This iterative process could also be used with the better algorithms listed in the links above for each step.
P: 29
I tried to use this one on your post above

 Δt = t1 - t0 initial velocity = Vy0 final velocity = Vy1= Vy0 + Ay Δt average velocity = 1/2 (Vy0 + Vy1) = 1/2 (Vy0 + (Vy0 + Ay Δt)) = Vy0 + 1/2 Ay Δt initial position = Py0 final position = Py0 + (average velocity) Δt = Py0 + (Vy0 + 1/2 Ay Δt) Δt = Py0 + Vy0 Δt + 1/2 Ay Δt2
But it ended up backfiring.

initialization before throwing
s = speed

Inside Timeframe function

set position.z = position.z + s*time+0.5*GRAVITY*(time*time)
set time = time - timeframe
HW Helper
P: 7,170
 Quote by wraithseeker initialization before throwing s = speed Inside Timeframe function set position.z = position.z + s*time+0.5*GRAVITY*(time*time) set time = time - timeframe
s = initial speed.z

set position.z = position.z + s*timeframe+0.5*gravity*(timeframe*timeframe)
set time = time + timeframe
 P: 29 Yep, s is initial speed z, I probably didn't get it clear for you sorry. time is actually the full time for the thrown ball but now edited to be 0 at start. position.z = position.z + s*timeframe+0.5*GRAVITY*(timeframe*timeframe) time = time + timeframe So how can time fit in now? I followed your example above and objects launched in the air never gets down.
HW Helper
P: 7,170
 Quote by wraithseeker Yep, s is initial speed z, I probably didn't get it clear for you sorry. time is actually the full time for the thrown ball but now edited to be 0 at start. position.z = position.z + s*timeframe+0.5*GRAVITY*(timeframe*timeframe) time = time + timeframe So how can time fit in now? I followed your example above and objects launched in the air never gets down.
Note that gravity is negative. It's -9.80665 meters/second2 or -32.174 feet / second2.
 P: 29 Gravity is -981 since it's converted to the game's units. What about that time variable that gets increased in the timeframe function?
HW Helper
P: 7,170
 Quote by wraithseeker Gravity is -981 since it's converted to the game's units. What about that time variable that gets increased in the timeframe function?
The time variable isn't being used in the other equations. You'd might use it to make a graph of position or velocity versus time.

 Related Discussions Precalculus Mathematics Homework 3 General Math 0 Precalculus Mathematics Homework 4 Introductory Physics Homework 1 General Math 6