Page 46 of 118
Re: Scripters cove
Posted: Tue Jun 05, 2012 10:51 am
by cim
Wildeblood wrote:How do I re-orient the player ship 180 degrees, so its nose is pointing straight back the way it came from?
Depending on which way up you want the ship to be afterwards, either
Code: Select all
player.ship.orientation = player.ship.orientation.rotateX(Math.PI); // as if pitched
or
Code: Select all
player.ship.orientation = player.ship.orientation.rotateY(Math.PI); // as if yawed
Re: Scripters cove
Posted: Tue Jun 05, 2012 10:54 am
by Capt. Murphy
Svengali wrote:I've just tried it with another Griff Cobra and indeed setShaders() doesn't do anything, but setMaterials() works.
Thanks Svengali, you are a star. Something else to keep me occupied when I'm supposed to be catching up on RL work.
Re: Scripters cove
Posted: Tue Jun 05, 2012 11:03 am
by Wildeblood
Thank you, cim.
Oi!
That sends me off at 90 degrees to the original course.
Re: Scripters cove
Posted: Tue Jun 05, 2012 12:22 pm
by Commander McLane
cim wrote:Wildeblood wrote:How do I re-orient the player ship 180 degrees, so its nose is pointing straight back the way it came from?
Depending on which way up you want the ship to be afterwards, either
Code: Select all
player.ship.orientation = player.ship.orientation.rotateX(Math.PI); // as if pitched
or
Code: Select all
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.
Re: Scripters cove
Posted: Tue Jun 05, 2012 12:24 pm
by Eric Walch
cim wrote:Depending on which way up you want the ship to be afterwards, either
Code: Select all
player.ship.orientation = player.ship.orientation.rotateX(Math.PI); // as if pitched
or
Code: Select all
player.ship.orientation = player.ship.orientation.rotateY(Math.PI); // as if yawed
Are you sure? I think that is rotating around the x-axis of the system, not that of the ship. For the ship you need:
Code: Select all
player.ship.orientation = player.ship.orientation.rotate(player.ship.vectorRight, Math.PI); // as if pitched
or
Code: Select all
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.
e.g.
Code: Select all
player.ship.orientation = player.ship.orientation.multiply([0, 1, 0, 0])
or
Code: Select all
player.ship.orientation = player.ship.orientation.multiply([0, 0, 1, 0])
Re: Scripters cove
Posted: Tue Jun 05, 2012 12:29 pm
by cim
Eric Walch wrote:Are you sure? I think that is rotating around the x-axis of the system, not that of the ship. For the ship you need:
Code: Select all
player.ship.orientation = player.ship.orientation.rotate(player.ship.vectorRight, Math.PI); // as if pitched
or
Code: Select all
player.ship.orientation = player.ship.orientation.rotate(player.ship.vectorUp, Math.PI); // as if yawed
Or, alternatively, you can
multiply the players orientation with the quaternion that describes a 180 degr. rotation.
Yes, sorry, that's correct. (Of course my test ship happened to be aligned to the system axes...)
Re: Scripters cove
Posted: Tue Jun 05, 2012 12:29 pm
by Thargoid
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.
Edit - It's obviously my day to be Ninja'd
Re: Scripters cove
Posted: Tue Jun 05, 2012 1:23 pm
by Wildeblood
This is also sending me off at a right angle:-
Code: Select all
{
player.ship.launch();
player.ship.orientation = player.ship.orientation.multiply([0, 0, 1, 0]); // Thanks, Eric Walch
}
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?
Re: Scripters cove
Posted: Tue Jun 05, 2012 1:28 pm
by Thargoid
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).
Re: Scripters cove
Posted: Tue Jun 05, 2012 1:35 pm
by Eric Walch
Wildeblood wrote: 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.
Re: Scripters cove
Posted: Tue Jun 05, 2012 1:38 pm
by Thargoid
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.
Re: Scripters cove
Posted: Tue Jun 05, 2012 1:40 pm
by Capt. Murphy
Eric Walch wrote:Wildeblood wrote: 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.
Sounds like a job for a frameCallback to me.
Re: Scripters cove
Posted: Sat Jun 09, 2012 1:13 pm
by Commander McLane
Eric Walch wrote:For [rotating] the ship you need:
Code: Select all
player.ship.orientation = player.ship.orientation.rotate(player.ship.vectorRight, Math.PI); // as if pitched
or
Code: Select all
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.
e.g.
Code: Select all
player.ship.orientation = player.ship.orientation.multiply([0, 1, 0, 0])
or
Code: Select all
player.ship.orientation = player.ship.orientation.multiply([0, 0, 1, 0])
This still doesn't seem to be correct.
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
Code: Select all
PS.orientation=PS.orientation.multiply([1, 0, 0, 1])
or (normalized)
Code: Select all
PS.orientation=PS.orientation.multiply([0.707107, 0, 0, 0.707107])
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.
Help needed!
Re: Scripters cove
Posted: Sat Jun 09, 2012 1:23 pm
by Thargoid
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).
Re: Scripters cove
Posted: Sun Jun 10, 2012 10:00 pm
by Eric Walch
Commander McLane wrote:or (normalized)
Code: Select all
PS.orientation=PS.orientation.multiply([0.707107, 0, 0, 0.707107])
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:
Code: Select all
PS.orientation=new Quaternion(0.707107, 0, 0, 0.707107).multiply(PS.orientation)
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.