I have a fixed initial velocity V(Vx,Vy,VZ) and a spot on higher ground E(Ex,Ey,Ez), my character must jump up there and he stands still at S(Sx,Sy,Sz). How Can I find the closest point to the character that can make him achieve the jump (same height of the character)?And If the spot Is not available how can check other solutions?
Jumping from lower ground
-
0Same heght stands for same plane of the character. Let assume that our character is in S(Sx,Sy,Sz) so the right jump spot must be J(Jx,Sy,Jz) so Sy e Jy must be equal on the same plane. The char is still because I must process the force in two steps: first move to jump spot and stop, Then when I say "Yes you can" jump with our fixed V :D – 2012-09-29
1 Answers
I guess if you wanted to include friction you would have mentioned it, so I'll assume that friction is supposed to be neglected.
Then the character's trajectory will be a parabola. The parabola traverses each $y$ coordinate $0$, $1$ or $2$ times. Thus, it makes no sense to ask for the closest point to the character from which to jump: Either there is no such point, or one such point, or, if there are two such points, we can ask which is closer.
The trajectory of a jump from $(J_x,S_y,J_z)$ with initial velocity $(V_x,V_y,V_z)$ (assuming that your capital 'Z' is a typo) is
$ \vec r(t)=\pmatrix{J_x\\S_y\\J_z}+t\pmatrix{V_x\\V_y\\V_z}-\frac12gt^2\pmatrix{0\\1\\0}\;. $
We can determine the time $t_E$ at which the target at $(E_x,E_y,E_z)$ is reached from the $y$ component:
$ S_y+t_EV_y-\frac12gt_E^2=E_y\;, $
$ t_E=\frac{V_y\pm\sqrt{V_y^2+2(S_y-E_y)g}}g\;. $
These solutions are real iff the kinetic energy $\frac12mV_y^2$ is greater or equal to the potential energy $mg(E_y-S_y)$ required to jump to the higher spot. We can then obtain $J_x$ and $J_z$ from
$ J_\alpha+t_EV_\alpha=E_\alpha\;, $
$ J_\alpha=E_\alpha-t_EV_\alpha=E_\alpha-\frac{V_\alpha}g\left(V_y\pm\sqrt{V_y^2+2(S_y-E_y)g}\right)\;. $
The easiest way to determine which of the two solutions is closer to $(S_x,S_y,S_z)$ is probably to compute them both and compare the distances.
Note that the $-$ sign yields a solution where the character reaches the target while moving upwards, whereas the $+$ sign yields a solution where the character reaches the target while moving downwards.
-
0Thanks a lot, will try to implement this and let you know if works. Finger crossed :D – 2012-09-29