Jump to content

SetWorldVelocity relevant to surface


Recommended Posts

*Edit title: I meant Relative to surface

Could someone clearify for me how the axle system works in KSP.

Say I would like to move a ship into a certain direction (say the runway for example)

how would I know what the Vector3D variables should be.

I understand that the ship is standing on the surface and that the vector3D is not an axle that's determined by the surface itself.

So I need to get the Vector3D of the body I'm on and use that for replotting my ships direction.

I looked it up at http://wiki.kerbalspaceprogram.com/wiki/API:CelestialBody

But couldn't really find what I was expecting.

Also I'm not sure how to get just one axle of an Vector3D. Something like Vector3D.x does not work.


public void Update(){
this.vessel.SetWorldVelocity (x?,y?,z?);
}
}

:) Would be a happy man if someone could explain it to me.

Edited by nahkranoth
Link to comment
Share on other sites

Figured out that I could use the rigidbody.AddRelativeForce() to apply a force in a relative direction.

The problem is that the vessel will destroy itself, because I want to accelerate it quickly and the forces get too big.

I have noticed that SetWorldVelocity does not destroy my craft because it does not apply a force to the rigidbody.

I have also found the rigidbody.rotation and I found something about converting that Quaternion.eulerAngles soo I could

get the rigidbody's rotation too the world and apply it to the SetWorldVelocity in theory.

In practice I haven't got that working.

Link to comment
Share on other sites

Aha, I got it working thanks to reading.

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

As for the runway, just apply the eastUnit to the SetWorldVelocity().

But! off coarse the next problem arises. As I start accelerating to around 700 m/s just above the surface of kerbin my ship just disappeares. I can see an error in the log:

NullReferenceException: Object reference not set to an instance of an object
at KerbalScript_1.testModule.OnStart (StartState state) [0x00000] in <filename unknown>:0

at Part.ModulesOnStart () [0x00000] in <filename unknown>:0

at Part+.MoveNext () [0x00000] in <filename unknown>:0

It has something to do with the part im building on (testModule)

Here is the code of the class:


public class testModule : PartModule
{
public int timer = 0;
public override void OnStart(StartState state)
{
this.vessel.rigidbody.freezeRotation = true;
}


public void Update(){

if (this.vessel == FlightGlobals.ActiveVessel) {
if (timer <= 350) {
Vector3d position = this.vessel.findWorldCenterOfMass();
Vector3d eastUnit = this.vessel.mainBody.getRFrmVel(position).normalized;
Vector3d upUnit = (position - this.vessel.mainBody.position).normalized;
Vector3d northUnit = Vector3d.Cross(upUnit, eastUnit); //north = up cross east

this.vessel.SetWorldVelocity((eastUnit*timer)+(upUnit*timer));

timer++;

}else{
this.vessel.rigidbody.freezeRotation = false;
}
}
}
}

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