June 23, 2024, 13:14:35

Author Topic: Target Bearings  (Read 8152 times)

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Target Bearings
« 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?

Better to look the fool by asking, then prove them right with ignorance.

Offline Arparso

  • Administrator
  • Lieutenant
  • *****
  • Posts: 558
  • Karma: 14
  • I can see you...
    • View Profile
    • http://arparso.de/nexus
Re: Target Bearings
« Reply #1 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.
« Last Edit: August 05, 2013, 02:34:07 by Arparso »

Offline The Old Dragon

  • Ensign
  • ***
  • Posts: 362
  • Karma: 6
    • View Profile
    • http://
Re: Target Bearings
« Reply #2 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.
Better to look the fool by asking, then prove them right with ignorance.