Scripters cove

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post 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
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: Scripters cove

Post 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. :wink:
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

Thank you, cim.

Oi!

That sends me off at 90 degrees to the original course.
Last edited by Wildeblood on Tue Jun 05, 2012 12:54 pm, edited 1 time in total.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Scripters cove

Post 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.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Scripters cove

Post 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])
Last edited by Eric Walch on Tue Jun 05, 2012 12:32 pm, edited 2 times in total.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post 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...)
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post 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 ;)
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post 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?
Last edited by Wildeblood on Tue Jun 05, 2012 1:36 pm, edited 1 time in total.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post 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).
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Scripters cove

Post 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.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post 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.
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: Scripters cove

Post 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.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Scripters cove

Post 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! :(
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post 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).
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Scripters cove

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