Always zero pitch in "look_at" orientation?

The place to discuss scripting and game modifications for X Rebirth.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
User avatar
MegaJohnny
Posts: 2195
Joined: Wed, 4. Jun 08, 22:30
x4

Always zero pitch in "look_at" orientation?

Post by MegaJohnny » Thu, 10. May 18, 15:29

I'm experimenting with AI scripts, and at the moment I want a ship to align facing a certain position, similar to how ships align before boosting to another zone in move.nohighway.

In the script, I use create_orientation to get a rotation facing the target position:

Code: Select all

<create_orientation name="$rot" orientation="look_at" refposition="$pos">
    <position object="this.ship" />
</create_orientation>
And then move_to to have the ship take on that rotation:

Code: Select all

<move_to object="this.ship" destination="this.zone" usehighways="false" forceposition="false" forcerotation="true" avoid="false" >
    <position object="this.ship" z="5m" />
    <rotation value="$rot" />
</move_to>
In one run of the program...
[-2303m, 642m, 859m] is the position of our ship...
[-4401m, -14477m, 15833m] is the target position.

You can see the target position is 15km away on the z-axis, and about 15km below on the y-axis too. So we should expect to see a pitch of about 45 degrees downwards. But printing the value of $rot gives [-7.9deg, 0, -0deg] for yaw, pitch and roll! And sure enough, the ship levels out completely during the move_to.

Am I missing something here? I know create_orientation has a "maxpitch" attribute, but it defaults to no pitch restriction. And there is no atan2 function for me to hack together a pitch value.

Anyone have any insights?

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Thu, 10. May 18, 19:58

Memory's fuzzy, but i vaguely remember a trick with create_orientation, but unfortunately can't remember what it is. Could you quickly try plotting the orientation from $pos?

Code: Select all

<create_orientation name="$rot" orientation="look_away" refobject="this.ship">
  <position value="$pos"/>
</create_orientation>
Would also be good to make sure that the two sets of coordinates are relative to the same thing, but that's not relevant in this case, i think, since the pitch looks way off as you said.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Thu, 10. May 18, 20:01

orientation works for me in another context:

Code: Select all

      <jump result="$firstresult" object="this.ship" zone="$beacon.zone" ignorefuel="$ignorefuel" commandaction="false" >
        <safepos allowyaxis="true" value="$beacon.position" radius="this.ship.size"/>
        <orientation refobject="$beacon" orientation="look_away"/>
        <interrupt_after_time time="0s"/>
      </jump>
the Ship is always facing away from the Beacon Object, including pitch up and down.. dir you try an explicit maxpitch if it changes behavior?
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

User avatar
MegaJohnny
Posts: 2195
Joined: Wed, 4. Jun 08, 22:30
x4

Post by MegaJohnny » Fri, 11. May 18, 04:10

w.evans wrote:Memory's fuzzy, but i vaguely remember a trick with create_orientation, but unfortunately can't remember what it is. Could you quickly try plotting the orientation from $pos?

Code: Select all

<create_orientation name="$rot" orientation="look_away" refobject="this.ship">
  <position value="$pos"/>
</create_orientation>
Would also be good to make sure that the two sets of coordinates are relative to the same thing, but that's not relevant in this case, i think, since the pitch looks way off as you said.
Thanks so much! Tried it and it works just as intended. That's a good trick!
UniTrader wrote:orientation works for me in another context:

Code: Select all

      <jump result="$firstresult" object="this.ship" zone="$beacon.zone" ignorefuel="$ignorefuel" commandaction="false" >
        <safepos allowyaxis="true" value="$beacon.position" radius="this.ship.size"/>
        <orientation refobject="$beacon" orientation="look_away"/>
        <interrupt_after_time time="0s"/>
      </jump>
the Ship is always facing away from the Beacon Object, including pitch up and down.. dir you try an explicit maxpitch if it changes behavior?
I think the difference is that when using refobject (which I used in a different code path) the pitch is used, but with refposition it isn't. I tried maxpitch set to 90deg with no visible difference, but it looks like w.evans' trick has done it.

Thanks for the responses - hope Ego have squashed this for X4!

Post Reply

Return to “X Rebirth - Scripts and Modding”