I've posted previously about spaceship control (https://www.gamedev.net/forums/topic/714454-using-physicsai-to-maneuver-a-spaceship-through-a-point-with-a-specific-velocity/) and since then have been looking at splines for spaceship control.
Basing my current attempt upon this answer here: https://gamedev.stackexchange.com/questions/162030/how-can-i-maneuver-an-ai-pirate-ship-for-a-sea-battle/162038#162038, I create a bezier curve with
- T = estimated time (currently just dist/velocity)
- V0 = velocity at the start
- VT = velocity goal (i.e. velocity we want at end of the curve)
- P0 = Ship pos
- PA (control point) = P0 + (⅓T * V0)
- P1 = Destination pos
- PB (control point) = P1 - (⅓T * VT))
This seems to make some sense, and means that I can move the control points depending on velocity, giving me the ability to specify the final velocity I want, which was one of the hard parts.
I'm having a few issues though;
- The ship should “thrust" in a direction to maneuver, applying an acceleration along its forward axis. Ignoring the rotation time, when a spline gives us velocities and accelerations along it, should we either
- Calculate a deltaV based on velocityOnCurve - currVelocity and push in that dir? Or
- Take accelerationOnCurve at our current time and just blindly accelerate in that dir, trusting the spline
- If I want to constantly recalculate my spline to handle that we likely do not perfectly estimate T, other impacts/imperfections etc, does that not mean my ship should constantly look at the spline at 0.0? If so, it seems to break things - we accelerate, which pushes PA control point forwards, which makes us accelerate more, etc, and we never actually turn.
- I don't understand how to apply constraints to this solution - for example the ships have a max speed and a max acceleration. I don't think I can constraint a spline to these right?
- So at least if I can detect when the max velocity / max acceleration on the spline exceeds the limits, I can “slide” the target point further along the line defined by
P1 → P1 + VT * infinity
until the max velocity/acceleration of the spline satisfies my constraints, basically pushing the point that we get on that line into the future until the ship doesn't have to accelerate beyond its limits.
- So at least if I can detect when the max velocity / max acceleration on the spline exceeds the limits, I can “slide” the target point further along the line defined by
- I tried simplifying things by calculating a spline once with my estimated T value, and using that each frame to calculate pos/vel/accel. If I set my ship to the pos at currT along the spline, it works okay, but if I try to use the velocity or acceleration, it shoots off into infinity. How does one… actually use the velocity/accel? Are they in some kind of space and need to be converted back to real space or something? The numbers look insanely high (and that's with a pretty high estimated T value that isn't exactly requiring the object be moving that fast, so it is extra surprising to see).
Appreciate any insights to these questions! It's getting there, I'm just not used to splines and don't fully get how to apply the numbers I'm getting from them to a physical world / control.
Thanks!