I’m making a 2D projectile that is going to hit the player whether the player is on the plane unlike an enemy straight forward projectile.
My issue can be simplified by extending a Path3D class a few more units and that’ll be done with.
So far, basing on high school (X,Y) math, I came up with this:
- Get the slope of the enemy point (X,Y) and the player point (X, Y).
var slope = (player.y - enemy.y) / (player.x - enemy.x);
- Using the slope and one of the points of the new extended coordinate and plug it in for the next:
//Note fixedEdge marks beyond the outer edge of the game scene
var newEndPointX = player.x >= 0 ? fixedEdge + 20 : -fixedEdge - 20;
var newY = slope * (newPointX - enemy.x) + enemy.y;
var endVector = new BABYLON.Vector3(newPointX, newY, 0);
- Apply this
endVector
to aPath3d
and have it fire away
When I tried this. There are too many problems. Many are hitting the target but they have very high extremes in terms of speed or distance or even hitting in the correct direction - in the opposite direction.
What am I doing wrong here? I’m clearly missing something here. Thanks for your time.