Nexus Modding > Scripting

Target Bearings

(1/1)

The Old Dragon:
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?

Arparso:
From the top of my head, this should be:


--- Code: ---// 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);

--- End code ---

Didn't test it and didn't write any Nexus script in a while, so syntax or functions might be a bit off.

The Old Dragon:
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.

Navigation

[0] Message Index

Go to full version