Recently, I acquired a cutting-edge 3D system along with a set of coordinates:
- Initial coordinates (x, y, z) for a rocket (located on the ground)
- Target coordinates (x, y, z) for the rocket's destination (also on the ground)
Here are some essential starting values:
- maximum_velocityZ = 0.5
- maximum_resVelocityXY = 0.3
- gravity factor = 9.81
I'm seeking guidance on how to determine the flight velocities
(velocityX, velocityY, and velocityZ)
for each update frame. Can you assist?
let maximum_velocityZ = 0.5
let maximum_resVelocityXY = 0.3
let gravity_factor = 9.81
let rocketPosition = {
x: 3,
y: 0,
z: 2
}
let rocketTarget = {
x: 7,
y: 5,
z: 8
}
let rocketVelocity = {
x: 0,
y: 0,
z: 0
}
let update = function() {
rocketPosition.x += rocketVelocity.x
rocketPosition.y += rocketVelocity.y
rocketPosition.z += rocketVelocity.z
let distanceX = (rocketTarget.x - rocketPosition.x)
let distanceY = (rocketTarget.y - rocketPosition.y)
let distanceZ = (rocketTarget.z - rocketPosition.z)
let factorXY = Math.abs(distanceX / distanceY)
rocketVelocity.x = maximum_resVelocityXY / Math.sqrt((1 / factorXY ** 2) + 1) * (distanceX > 0 ? 1 : -1)
rocketVelocity.y = maximum_resVelocityXY / Math.sqrt((factorXY ** 2) + 1) * (distanceY > 0 ? 1 : -1)
rocketVelocity.z = maximum_velocityZ * distanceZ;
rocketVelocity.z /= gravity_factor;
console.log("x:", Math.round(rocketPosition.x), "y:", Math.round(rocketPosition.y), "z:", Math.round(rocketPosition.z))
}
setInterval(update, 300)
This code reflects my current progress. I believe I'm heading in the right direction with X and Y velocities, but I'm facing challenges with Velocity Z. The trajectory in 3D space appears far from realistic. Any guidance or suggestions would be greatly appreciated. Wishing you a happy new year - may it soar high like the rocket!