player.ship.orientation = player.ship.orientation.rotateY(Math.PI); // as if yawed
Unfortunately that's not true. Just try it by stopping immediately after launch and then using it in the console. It results in some rotation that is indeed reversed if you perform the same command again, but it's not a 180 degree rotation. I haven't figured out yet what the correct calculation would be, though.
player.ship.orientation = player.ship.orientation.rotate(player.ship.vectorUp, Math.PI); // as if yawed
Or, alternatively and more efficiently if you do a lot of rotations, you can multiply the players orientation with the quaternion that describes a 180 degr. rotation.
player.ship.orientation = player.ship.orientation.rotate(player.ship.vectorUp, Math.PI) will do the job.
McLane is right - X/Y/Z in the previous script example is the universes axis set, not the ships (which is the axis set you want). Those would be player.ship.vectorRight, player.ship.vectorUp and player.ship.vectorForward respectively.
I don't know whether it's collision avoidance doing it? I'm trying to simulate backing out of the dock, rather than launching nose first. So I want to re-orient the ship so forward view is looking at the station, but not change its motion, so it's travelling backwards away from the dock. However...
TypeError: player.ship.speed is read-only
So, if it did rotate 180 degrees, it would only fly back into the dock anyway. So my second question is how do I give it a thrust or velocity or what-have-you, in the original direction away from the dock, slightly faster than the launch speed?
Last edited by Wildeblood on Tue Jun 05, 2012 1:36 pm, edited 1 time in total.
You'll have to reverse the ship's velocity too. If you spin the ship around without doing so, then you'll end up basically going in the opposite direction (back into the dock in this case).
I'm trying to simulate backing out of the dock, rather than launching nose first. So I want to re-orient the ship so forward view is looking at the station, but not change its motion, so it's travelling backwards away from the dock.
This will not be possible for a players ship. The ships thrust will always try to accelerate the ship to make the ship fly forward. For npc you can do a trick by setting thust to zero and than give it a velocity in the desired direction. Without thrust, a ship can't correct this backward motion. But to prevent scripts from fiddling with the player, thrust is read-only for player ships. That means that any backward velocity you give a player, will be fast reduced to zero.
It's not that fast a reduction, presuming the velocity given is large enough (plus on launch the player ship speed isn't max'd anyway). Look at retro rockets for example - they can shift the player ship quite a way before the effect wears off.
I'm trying to simulate backing out of the dock, rather than launching nose first. So I want to re-orient the ship so forward view is looking at the station, but not change its motion, so it's travelling backwards away from the dock.
player.ship.orientation = player.ship.orientation.rotate(player.ship.vectorUp, Math.PI); // as if yawed
Or, alternatively and more efficiently if you do a lot of rotations, you can multiply the players orientation with the quaternion that describes a 180 degr. rotation.
I am currently trying to rotate a ship 90 degrees around its own z-axis (= roll). I'm experimenting with the player ship via the console. According to Erics recipe (and to everything else I have understood) it should be done by
However, it doesn't work! In the special case of my ship being aligned to the system's z-axis it does work, but in all other cases I still seem to turn around the system's z-axis, not my own. You can test it by pointing your ship's nose to the planet and entering the above command.
Use the other version - player.ship.orientation = player.ship.orientation.rotate(player.ship.vectorForward, Math.PI); . That makes no reference to the universe, and specifically gives the rotational axis based around the ship (the forward direction in this case).
However, it doesn't work! In the special case of my ship being aligned to the system's z-axis it does work, but in all other cases I still seem to turn around the system's z-axis, not my own. You can test it by pointing your ship's nose to the planet and entering the above command.
You are right, my code was not correct. The multiplication with a quaternion was right, as that is how oolite lets fly all ships. I just tested once and apparently I was in a correct system to make it work. I had the order wrong and the order is important in quaternion multiplications. What does work it:
It rotates you around the z axis. Normalising is essential for a correct result. In some cases oolite does it for you if it knows it needs a normalised quaternion. In this case it is just math and Oolite does not know you want to use it in code that needs normalisation first.