Nexus Skirmisher

Nexus Modding => Scripting => Topic started by: The Old Dragon on August 04, 2013, 00:02:18

Title: Target Bearings
Post by: The Old Dragon on August 04, 2013, 00:02:18
Hi All,

I'm trying to to get the bearings to a target location from my starting point (i.e. the heading and pitch required to point the ship at the target) and not having much luck so far. Getting the X,Y,Z coordinates isn't a problem, can anyone help?

Title: Re: Target Bearings
Post by: Arparso on August 05, 2013, 02:30:14
From the top of my head, this should be:

Code: [Select]
// Calculate a vector from your ship's position to your target:
targetVector := VSub(Target.Position, Ship.Position);

// now calculate the heading and pitch from that
// result will be:
//          targetRotation.X => heading
//          targetRotation.Y => pitch
//          targetRoation.Z => bank (always 0 after V2Rot)
targetRotation := V2Rot(targetVector);

// make the ship point in the given direction:
ForceOrient(Ship, targetRotation.X, targetRotation.Y, whateverBankYouWant);

Didn't test it and didn't write any Nexus script in a while, so syntax or functions might be a bit off.
Title: Re: Target Bearings
Post by: The Old Dragon on August 05, 2013, 14:45:51
Cheers Arparso,

Apart from a couple of syntax errors, works like a charm  :)
My attempts to calculate the angles with maths was being somewhat thwarted to say teh least and was a lot more clunkier than this.

Thank you.