Jump to content

The state of Vessel fields in OnUpdate and OnFixedUpdate


Croc

Recommended Posts

Hi all,

The values in various Vessel fields, for example, acceleration, longitude etc seem to oscillate between a value i'd expect to see and another random value which looks like junk. For example, i'm examining acceleration.x on each update and it sawtooths between the expected value and 0. Longitude does the same except it oscillates between the expected value and a negative number.

I wondered if perhaps it is not reliable to use these fields or use them in update. If I examine them in OnFixedUpdate, the acceleration vector is always 0,0,0 which suggests it is reset before some calculations take place.

Any pointers appreciated!

Link to comment
Share on other sites

Vessel.transform should give you some info about your craft as far as momentum is concerned. For lat and lon, use CelestialBody.GetLatitude(this.vessel.findWorldCenterOfMass()) and CelestialBody.GetLongitude(this.vessel.findWorldCenterOfMass()).

As for whether or not the Lat and Lon values will be within +/- 180 I don't know. So far during my tests, that seems to be the case.

Ah, actually, there's a few methods in Vessel that will give you velocity: GetObtVelocity() and GetSrfVelocity(). I hope you can distinguish when to use each.

Link to comment
Share on other sites

In short, OnUpdate is when graphics are done and OnFixedUpdate are when physics are done. Anything related to physics should happen during OnFixedUpdate.

Here is a helpful API list for everything you should need to know about the vessel: http://wiki.kerbalspaceprogram.com/wiki/Category:Community_API_Documentation

Example code:

http://wiki.kerbalspaceprogram.com/wiki/Module_code_examples

Good luck!

Link to comment
Share on other sites

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...