Jump to content

Timewarp Rotation Fix


skykooler

Recommended Posts

  • 2 weeks later...

Yes, there is. I've been putting it off because dealing with quaternions hurts my brain. That said, I have two major goals for the next release:

  1. Fix rotational speed accumulation
  2. Make SAS planet-synchronous (i.e. enable orb-rate rotation). This one is the one I am having a hard time with due to the aformentioned quaternions. Anyone who has a background in physics, I'd appreciate your help!

Link to comment
Share on other sites

Sounds like you need to rotate around the normal vector of your orbit. So each tick do maybe (spitballing, pseudocode inside the AngleAxis() )

vessel.orientation *= Quaternion.AngleAxis(360 / orbit.period * deltaTime, orbit.normal)

Link to comment
Share on other sites

Sounds like you need to rotate around the normal vector of your orbit. So each tick do maybe (spitballing, pseudocode inside the AngleAxis() )

vessel.orientation *= Quaternion.AngleAxis(360 / orbit.period * deltaTime, orbit.normal)

This will be useful for long ion engine burn (with close-to-reality thrust of course)... mmm...

Link to comment
Share on other sites

So, I've spent about five hours today trying to get orb-rate rotation to work, and so far everything either is completely wrong or only works if your ship starts out in a certain orientation. Not really sure what to do at this point; if anyone has any ideas, please PM me.

Link to comment
Share on other sites

So, I've spent about five hours today trying to get orb-rate rotation to work, and so far everything either is completely wrong or only works if your ship starts out in a certain orientation. Not really sure what to do at this point; if anyone has any ideas, please PM me.

perhaps you need to swap x & y axes (or perhaps x & z or y & z axes, I don't remember that clearly) for the rotation because the coordinate system used by orbit is different from the one used by vessel.GetWorldPosition() IIRC.

Link to comment
Share on other sites

yes, I did see that in the documentation, but even after swapping y and z axes it isn't working right - it will work if you are pointing prograde and are level to the horizon, but if you're pointed any other way it rotates in some crazy direction. It's like it's mixing up world-space and local-space rotations somehow.

Link to comment
Share on other sites

I spent alot of time fiddling with it, and I got it to work while facing in any direction. Now, the only problem is that if the warp rate is less than 50x, the rotation between updates is so small that it just registers as zero. I'll post the code once I figure that bit out.

edit: In case it helps, here's the important bit:


Vector3 rotAxis = Quaternion.Inverse (activeVessel.transform.rotation) * activeVessel.orbit.GetOrbitNormal().xzy;
activeVessel.SetRotation (activeVessel.transform.rotation * Quaternion.AngleAxis(-deltaRotAngle, rotAxis));

edit 2: Strange.. this only works in equatorial orbit. In a polar orbit, it works fine until you cross over the pole, then it goes crazy.

edit 3: Nevermind, I think it does totally work. It just looked weird because of the way the camera and navball orientation rotates when you cross a pole. Also, the delta rotation angle issue I mentioned had to do with the way I was calculating the angle. I went back to use the method that NathanKell suggested and it works better.

void FixedUpdate()
{
activeVessel = FlightGlobals.ActiveVessel;

if(TimeWarp.CurrentRate > 1 && TimeWarp.WarpMode == TimeWarp.Modes.HIGH)
{
float deltaRotAngle = (float) (360/activeVessel.orbit.period * TimeWarp.fixedDeltaTime);
Vector3 rotAxis = Quaternion.Inverse (activeVessel.transform.rotation) * activeVessel.orbit.GetOrbitNormal().xzy;
activeVessel.SetRotation (activeVessel.transform.rotation * Quaternion.AngleAxis(-deltaRotAngle, rotAxis));
}
}

It shakes alot in Update; works better in FixedUpdate

Edited by BahamutoD
Link to comment
Share on other sites

Version 0.3 released!

Orb-rate rotation has been added! This means, if you turn on SAS, you will now complete one rotation per orbit. If you are in a roughly circular orbit, this means you will stay in the same orientation relative to the planet (and to your navball); however if you are in an eccentric orbit the planet will appear to move back and forth relative to you.

Link to comment
Share on other sites

Did you stick the latest source code in the download? I want to see if I can look into the rotation speed accumulation issue.

Erm, oops, I left the old source code in there; I'll fix it when I get home this evening.

I have a request: can you make this option toggleable?

By using a toolbar icon, so that you can select wich craft should rotate and wich ones shouldn't.

Good idea. I'll look into that for v0.4.

Just to clarify the speed increase when coming out of warp bug hasn't been solved right?

No, not yet. I'm still not sure what's causing it.

Link to comment
Share on other sites

Erm, oops, I left the old source code in there; I'll fix it when I get home this evening.

Good idea. I'll look into that for v0.4.

No, not yet. I'm still not sure what's causing it.

Thanks for the reply, while this is a great realism mod, i found that it's interfering with MechJeb's way of executing maneuver notes.

Link to comment
Share on other sites

Thanks for the reply, while this is a great realism mod, i found that it's interfering with MechJeb's way of executing maneuver notes.

This is a known issue; MechJeb abuses the timewarp system to halt rotation. I talked to the maintainer several months ago, but I forget what the consensus was.

Also: I've fixed the .zip in the first post to have the new source code, if anyone wants to try and figure out what's causing the acceleration.

Link to comment
Share on other sites

I am so glad this mod is fixed, adding rotation was not fun. I do have one small complaint though :S

When I come out of time warp with SAS on, the SAS system suddenly decides it is not pointing the right direction and takes evasive action. If I tap the "F" key immediately out of warp there is little consequence. I would recommend having the mod do this (reset the SAS orientation, or momentarily disable it out of time warp) automatically if possible.

Other than that, I am super glad to have this mod; as I have been playing with greatly reduced pod torque and the temptation to abuse time warp has caught me off guard sometimes.

Link to comment
Share on other sites

This is a known issue; MechJeb abuses the timewarp system to halt rotation. I talked to the maintainer several months ago, but I forget what the consensus was.

Also: I've fixed the .zip in the first post to have the new source code, if anyone wants to try and figure out what's causing the acceleration.

Cool. Not sure I'd be able to figure it out but I'll try.

I am so glad this mod is fixed, adding rotation was not fun. I do have one small complaint though :S

When I come out of time warp with SAS on, the SAS system suddenly decides it is not pointing the right direction and takes evasive action. If I tap the "F" key immediately out of warp there is little consequence. I would recommend having the mod do this (reset the SAS orientation, or momentarily disable it out of time warp) automatically if possible.

(edited)


activeVessel.vesselSAS.LockHeading(activeVessel.rotation, true);

Will set the sas target to wherever it is currently facing, to prevent the jerk when coming out of timewarp after rotating.

Edited by BahamutoD
Link to comment
Share on other sites

  • 2 weeks later...

I really like this mod.

Just tested to see if it also does the Dzhanibekov effect (a.k.a. the tennis racket theorem) during time warp. I did not expected it to work and it did not, as can be seen in this video:

I also do not think that this mod should though, because I do not think it has any real applications and most crafts might not even have an unstable axis of rotation.

Link to comment
Share on other sites

Regarding the angular momentum glitch. Is the math wrong somewhere or is floating point demons the culprit?

I have a bat-guano crazy thought that could address both and don't even know if it's practical or even possible. The idea involves pointing forces applied to the physical parts in the direction of the origin of dummy objects corresponding to the same objects on rails (a duplicate in empty form, a collection of origins). Instead of trying to distribute momentum manually this would use information from an on rails object to drag the craft and parts until they matched rotation speed (when the origins line up and become stable).

Link to comment
Share on other sites

  • 2 weeks later...
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...