Jump to content

Setting ship world velocity every physics frame?


Recommended Posts

How do I do this? I'm trying to make the ship fly at a constant velocity in the direction it's pointed, as long as a button in a part's right click menu is enabled. Basically a warp drive/inertial damper of sorts. I've tried using the following:

bool active = false;
  
//Gui stuff for controlling the "active" variable goes here

public void OnUpdate()
{
  if(active == true)
  {
    vessel.SetWorldVelocity(new Vector3d(1.0d, 1.0d, 1.0d)); //Placeholder values for the speed
  }
}

However, instead of setting the ship's velocity like the API documentation says it will, SetWorldVelocity() adds to the ship's velocity and it just keeps accelerating forever. I don't think it's supposed to do that considering there's also a ChangeWorldVelocity() function. The ship will slowly accelerate even when I set the velocity argument to Vector3d.zero. How do I make the world velocity vector remain constant, while still being able to control pitch, roll and yaw to steer the ship?

Edit: I also tried putting the SetWorldVelocity() call in the GUI part so it's triggered whenever I hit the button in the part's right click menu, and repeatedly hitting the button adds to the velocity instead of setting it to a certain value like it should.

Edited by CaptainKorhonen
Link to comment
Share on other sites

Messing with the velocity directly will always lead to strange behaviors since you will fight with the orbits and FlightIntegrator.

SetWorldVelocity is one of those calls in KSP that should not be public, or even exist at all. The way it does things make me think it a a remmenant of the pre krakensbane era. 

 

If you want a constant velocity while maintaining control then write a cheat engine that provides the proper acceleration.

Edited by sarbian
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...