Jump to content

KOS wait until facing = prograde


thekapm

Recommended Posts

I'm trying to lock steering to ship:prograde/retrograde, and then wait until facing = prograde. The problem is that the facing will never actually be equal to prograde or retrograde when locked like that, so the ship sits on the direction infinitely.

I want this script to be universal regardless of how long it takes a ship to turn.

My code looks like this:

lock steering to ship:prograde.

wait until ship:facing = ship:prograde.

 

Link to comment
Share on other sites

Not sure what KOS syntax is, but the operation you're looking for is a vector dot product

Assuming the vectors are normalised. ie. length of 1:

  • 1.0 == perfect alignment
  • 0 == perpendicular (90 degrees)
  • -1.0 == perfect opposition
  • >0.999 = <2.5 degrees of seperation
  • More generically: cos-1(result) = angle
Edited by Crzyrndm
Link to comment
Share on other sites

I use this function :

function waitAngle{
  parameter vector.
  lock steering to vector.
  wait until vang(ship:facing:forevector,vector) <2.
}

In your case you only need : wait until vang(ship:facing:forevector,prograde) < 2.

vang calculate the angle between two vectors. Facing is a direction, that's why you need to use  ship:facing:forevector. (see kOS documentation for more explanation).

I find that 2° is generally  good enough, but you can use whatever threshold you want.

 

-----------

Edit: If you want to use the vector dot product as suggested above by @Crzyrndm. Here we go :

wait until vdot(ship:facing:forevector,prograde) > 0.999.

If it doesnt work check if the prograde and facing are unatary vector. If not, you need to multiply 0.999 by their magnitudes.

 

Edited by Chabadarl
Link to comment
Share on other sites

That is a lot easier than what I finally came up with. Here is what I did:

declare function pcheck
{
	set a to ship:prograde:pitch.
	set b to ship:prograde:yaw.
	set c to ship:prograde:roll.
	lock steering to R(a,b,c).
	WAIT UNTIL (ship:facing:pitch >= (round(a) - 5) AND ship:facing:roll >= (round(c) - 5)) AND (ship:facing:pitch <= (round(a) + 5) AND ship:facing:roll round(c) + 5)).
}

I had found out that the pitch and roll, when rounded, stay the same for prograde and retrograde. So I made it wait until they were equal. Then after the function in my code I added a lock steering to ship:prograde, because by then they were close enough that it could throttle without spinning all over the place.

Link to comment
Share on other sites

  • 2 months later...

1st:
when lock steering for a burn, you usually don't need to roll, this can be done by:
lock steering to lookdirup(MYVECTOR, ship:facing:topvector).

2nd:
you can then burn a long as the angle is low enough
lock throttle_ to nextnode:burnvector:mag*mass)/(maxthrust+0.01)*1.5.
lock throttle to min( vectorangle(MYVECTOR,ship:facing:vector)*-1+2 ,throttle_).

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