Looks really coherent! good job
So Iāve recently thrown out most of the old spaceship steering code and replaced it with PID controllers and a slightly different interface. It was actually rather simple once I had all the angular targets defined properly.
Now all rotations are done with physics forces only and with no more angular velocity setting hackery.
I even have the option to have ships bank into corners, but that just makes everything less stable for very high twr ships and causes the nose to rise slightly.
Hereās the PID library I found btw:
So you run a PID controller for each axis?
Yep, thatās right. Roll always tries to correct to vertical (or the banking angle that scales with the turn), pitch and yaw take the values from the mouse point vector and convert it to local angles, then the system tries to match them.
Brilliant! I am so stealing this
Hereās some of the main math (with some stuff generalized) as well if it comes in handy:
Node ship;
float force;
Vector3f foreward = ship.getLocalRotation().getRotationColumn(2);
Vector3f yaw = ship.getLocalRotation().getRotationColumn(1);
Vector3f pitch = ship.getLocalRotation().getRotationColumn(0);
float[] angles = new float[3];
angles = ship.getLocalRotation().toAngles(angles);
// yaw and pitch
float dist = CPU.game.getCamera().getViewToProjectionZ(5000);
Vector3f targetpos = CPU.game.getCamera().getWorldCoordinates(new Vector2f(mau5pos.x, mau5pos.y), dist).clone();
Vector3f tgt = ship.worldToLocal(targetpos, new Vector3f()).normalizeLocal();
Vector3f local = new Vector3f(tgt.x,0f,tgt.z);
local.normalizeLocal();
float pad2 = -FastMath.atan2(local.x, local.z);
float x = ship.yawPID.getOutput(pad2*10f,0f);
physicsrigidbody.applyTorque(yaw.mult(force*x));
float y = ship.pitchPID.getOutput(FastMath.asin(tgt.y)*10f,0f);
physicsrigidbody.applyTorque(pitch.mult(force*y));
//roll
float tilt = FastMath.clamp(-x, -45*FastMath.DEG_TO_RAD, 45*FastMath.DEG_TO_RAD); //90 deg banking limit example
if(FastMath.abs(x) < 0.4)
tilt = 0f;
float corrector = ship.rollPID.getOutput(angles[2],tilt);
physicsrigidbody.applyTorque(foreward.mult(force*corrector));
I have Z defined as ship forward and Y is up.
I am currently ārolling my ownā. I was unable to find anything suitable available already.
Mithrin
The example for BigBanana looks like this. My game is already using it
(Removed offending image)
What, image upload works again???
Oh, time to switch over to Lemur and the big banana then!
Maybe I can port some of my cool widgets over to this UI library. Weāll see.
We had to turn it on for avatars to work. If people keep using it for screenshots then I guess weāll have to turn it off again.
Fixed, but⦠discourse hates monekeys
While Iām using it, I donāt reccommend yet to use⦠might do more harm than good in its current form.
Star Trek Beyond, directed by Mel Brooks
Turns out PID controllers work on other things as well
Edit: more pics:
And some reaction wheels I had to add to stop huge ships from turning like a building, despite being the same size:
? Look like gyroscopic stabilizers. Could you explain a little more about those?
Well in the real life physics sense theyāre flywheels that can be spun in order to induce angular momentum, used on satelites and the like. Supposedly the difference from gyroscopes is that they donāt spin constantly but only when you need to rotate and are fixed in place.
Hereās a sort of real use case demonstration I guess.
They do have a few drawbacks though, you need one per each axis, they can only induce a very limited rotation speed and arenāt exactly the most reliable things ever.
To keep things simple Iāve more or less just copied the KSP simplification - that means one wheel can add forces to all axes and just pretty much acts as a rotational thruster while only using electric power.
I didnāt want sideways attached engines ruining sleek ship designs
So my show off is not exactly spectacular after seeing @MoffKalast update there or any of the other updates earlier BUT Iām fairly proud of my progress at learning shaders.
So I set myself a simple goal after reading a buncha material on how this stuff works. Goal #1⦠Load 2 cubes one with a custom material that shifts everything 1 unit along the X Axis.
Then I decided to muck with applying changes over time. Which got me to making this morphing cube wireframe that is sorta sensually moving.
So ya. The list of people that I really need to thank for listening to my questions and taking time to answer them is kinda huge. So thanks to all!
Nice. How did you offset the vertex in the first screenshot?
Just add a vector to the input inPosition before doing the transforms.
E.g. :
vec3 pos = inPosition + vec3(1.0, 0.0, 0.0);
Stuff like this shouldnāt work though:
inPosition.x += 1.0;
Since any input values are effectively final iirc.
More or less I did exactly what @MoffKalast said. Iām not at my computer right now but when I get a chance (tomorrow night) I can show you line for line if you want.
Does the winnebago go at ludicrous speed?