|
2 registered members (TipmyPip, izorro),
556
guests, and 2
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Moving on a parable
#144735
07/31/07 20:25
07/31/07 20:25
|
Joined: Apr 2002
Posts: 4,801 Richmond B.C., Canada
Captain_Kiyaku
OP

Dichotomic
|
OP

Dichotomic
Joined: Apr 2002
Posts: 4,801
Richmond B.C., Canada
|
Hi, i have a small problem to calculate a parable movement. I want the play (A in my picture) to jump to vector B. While doing it, he has to arrive the height C.  I first scan the bottom infront of the play (100 quants) and calculate the height of the new position. My problem is to create this parable and how to move the player on it. Can anyone help me or gimme some hints there? Thanks in advance!
My Blog"Tag und Nacht schrei ich mich heiser, Wind weht alle Worte fort, Tag und Nacht schrei ich mein Krähenwort!"Subway To Sally - Krähenkönig
|
|
|
Re: Moving on a parable
[Re: demiGod]
#144740
08/01/07 06:19
08/01/07 06:19
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
vertical velocity at any point on the parabola, v = u + at (where "u" is initial vertical velocity, "a" is acceleration [in this case gravity] and "t" is time). integrating this to find dispacement gives: z = ut + 0.5att; if we start at the top of the parabola (to simplify the equation) -z = 0.5att; (no initial vertical velocity) tt = -2z/a; t = sqrt(-2z/a); now, -z/a is positive because a is negative (gravity). if we treat gravity as positive, then z has to be positive because the axes need to be in the same direction: t = sqrt(2z/a); now we know the time to reach the top of the parabola. v = u - at; (we're treating a as positive; we can either do "u - at" or "-u + at" because v has to decrease with time) u = v + at; (we know v = 0, and we know a and t) u = at; now for the lateral initial velocity (let w = lateral velocity because v has already been used): w = d/(2t); (velocity = distance / time) there is no acceleration involved, because gravity is perpendicular to w. we doubled t because t is the time to reach the top of the parabola, and it takes the same time to come back down. d is the distance from A to B in your diagram. initial velocity is w + u. in code: Code:
var t; // time var a; // gravity. set to a positive value var z; // the height you want to jump to VECTOR d; // this is the vector from A to B in your pic var u; // initial vertical velocity VECTOR w; // initial lateral velocity VECTOR speed; // i don't know what vector you are using for your player's speed, but this represents it for this example.
...
// set a to positive gravity, z to the height of C in your pic, and d to the // vector from point A to B, then the following should calculate the required velocity:
t = sqrt(2*z/a); u = a*t; t = 1/(2*t); vec_set(w,d); vec_normalize(w,t); vec_set(speed,w); speed.z = u;
feel free not to declare most of those variables and use constants instead (and substitute into the code at the end). i'm pretty sure this would work. julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: Moving on a parable
[Re: JibbSmart]
#144741
08/01/07 07:51
08/01/07 07:51
|
Joined: Apr 2002
Posts: 4,801 Richmond B.C., Canada
Captain_Kiyaku
OP

Dichotomic
|
OP

Dichotomic
Joined: Apr 2002
Posts: 4,801
Richmond B.C., Canada
|
First, thanks a lot for your help and your very good description.
Second, i'm not able to get it to work.
Somehow speed.z is always "10" and doesn't change at all. I calculated the vector d with
vec_set(d, vNewPos); vec_sub(d, my.x);
If this is wrong, please tell me. Then i use your calculations in a while loop so i can move along it, but it only moves upwards. I'm not sure if i have to refresh the vector d in the loop, but i tried it too.
My Blog"Tag und Nacht schrei ich mich heiser, Wind weht alle Worte fort, Tag und Nacht schrei ich mein Krähenwort!"Subway To Sally - Krähenkönig
|
|
|
Re: Moving on a parable
[Re: Captain_Kiyaku]
#144742
08/01/07 09:51
08/01/07 09:51
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
this is correct  sorry, i didn't explain the implementation well enough. my code will calculate the strength of the jump for you -- do it once when you want to start the jump. use "accelerate(speed.z,-a,0);" every frame to handle downwards acceleration due to gravity (this makes it a parabola) and store actual movements in a separate VECTOR which you can edit according to time: Code:
VECTOR moveSpeed;
...
vec_set(moveSpeed,speed); // do this just before your c_move, and use moveSpeed instead of speed vec_scale(moveSpeed,time_step);
i hope this works  if it doesn't it could just as likely be my fault as yours. i can't see any fault in my calculations, but i'm still worried there is. questions in my school's physics and maths usually have different givens and different unknowns. julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: Moving on a parable
[Re: JibbSmart]
#144743
08/01/07 10:39
08/01/07 10:39
|
Joined: Apr 2002
Posts: 4,801 Richmond B.C., Canada
Captain_Kiyaku
OP

Dichotomic
|
OP

Dichotomic
Joined: Apr 2002
Posts: 4,801
Richmond B.C., Canada
|
this looks more like a parabel now  Though there is one problem left: When i jump, i touch the height of C. But i don't know how i get the horizontal speed to reach the x-position of C when im at the Y-Position. i thought w will do this but it just jumps up and down, without moving forward at all.
My Blog"Tag und Nacht schrei ich mich heiser, Wind weht alle Worte fort, Tag und Nacht schrei ich mein Krähenwort!"Subway To Sally - Krähenkönig
|
|
|
Re: Moving on a parable
[Re: Captain_Kiyaku]
#144744
08/01/07 11:04
08/01/07 11:04
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
Code:
t = sqrt(2*z/a); u = a*t; t = 1/(2*t); vec_set(w,d); vec_normalize(w,t); // this sets the horizontal jump speed vec_set(speed,w); speed.z = u;
i was pretty sure this would set the correct horizontal speed. your code: Code:
vec_set(d, vNewPos); vec_sub(d, my.x);
i would've thought this would set it right. are you sure vNewPos is the right place? i'm not sure what could be wrong with the horizontal motion. are you saying that it reaches the y-position but not the x-position? julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
|