Hello again guys and gals.
Im on my last leg of coding for this section and am starting the part I’ve put off for a while now.
So here we go.
If my character if moving right (x+) at a magnitude of 85 and another object approaches from behind moving 90 (x+) and strikes the player, the difference in velocity is a mere 5. Now if that same enemy if moving left and hits head on the difference in velocity is of course far higher (90+85 = 175).
This may be the only time you’ll ever see me ask before I’ve produced code, and here’s why.
In the past I’ve had to measure change in velocity to get direction, and then use selection to determine which math to use. I.E.
double thisDirSpeed = thisDirandSpeed(x,y,lastx,lasty);
double thatDirSpeed = thatDirandSpeed(that.x,that.y,that.lastx,that.lasty);
if(this.isMOvingLeft = true && that.movingLeft == true)
{
differenceOfSpeed = thisDirSpeed - thatDirSpeed;
}
etc…(obviously pseudoCode)
Now, is there a way in unity, or at least a pre defined routine somewhere which can do this
A.Easily
B. Cheaply, as in without grabbing values and calculating every single tick?(as this requires that that.object actively tracks it’s last position, something which becomes expensive with 80 moving moving objects in proximity to a player)…
C: Has medium high to very high fidelity
D: Can be ported to multiple objects without much alteration…
I’ve written something similar in C++ while in school, and in Java(like regular real java) on a later project. In both cases, performance degraded quickly when objects came into calculation range.
I will be grateful if anyone can point me in the right direction. I am somewhat sure in the vast library of unity awesomeness there is a simple and solid method to get this done without re-coding the wheel.
Thanks in advance!!!