Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
Richard

Registered:
Posts: 126
Reply with quote  #1 
Hi,
Is it possible to get the bearing of a ship in relation to the player ship?

This data exists in the game (the science officer can access it just pointing the cursor to a point in the map), so I think it isn't that hard to use it in a script.


Thanks
ryleyra

Registered:
Posts: 2,870
Reply with quote  #2 
Well, it's not exactly possible. What you can do, however, and what I have done in my own scripts is to calculate the general direction of the other ship, to the nearest 90 or 45 degrees. In other words, you can determine if the target ship is north, sound, east or west of the player ship.

Here's a somewhat modified example based the code I used to place a wreck in a minefield in my simple sandbox:


  <event>
    <!-- divide minefields into 45 degree arcs and place wreck in that arc -->
    <if_variable name="missionSelected" comparator="EQUALS" value="7" />
    <if_variable name="missionPhase" comparator="EQUALS" value="4" />
    <if_variable name="minesValue" comparator="GREATER" value="0" />
    <if_variable name="minesDeg" comparator="GREATER_EQUAL" value="0" />
    <if_variable name="minesDeg" comparator="LESS" value="45" />
    <if_not_exists name="WRK" />
    <set_variable name="randomZ" randomIntLow="-minesDist/10" randomIntHigh="minesDist/10" />
    <set_variable name="randomX" value="minesX*2-minesDist*0.7-randomZ" />
    <set_variable name="randomZ" value="minesZ*2-minesDist*0.7+randomZ" />
    <create name="WRK" type="monster" monsterType="8" x="randomX" y="0" z="randomZ" angle="0" age="1" />
  </event>
  <event>
    <if_variable name="missionSelected" comparator="EQUALS" value="7" />
    <if_variable name="missionPhase" comparator="EQUALS" value="4" />
    <if_variable name="minesValue" comparator="GREATER" value="0" />
    <if_variable name="minesDeg" comparator="GREATER_EQUAL" value="45" />
    <if_variable name="minesDeg" comparator="LESS" value="90" />
    <if_not_exists name="WRK" />
    <set_variable name="randomZ" randomIntLow="-minesDist/10" randomIntHigh="minesDist/10" />
    <set_variable name="randomX" value="minesX*2-minesDist" />
    <set_variable name="randomZ" value="minesZ*2+randomZ" />
    <create name="WRK" type="monster" monsterType="8" x="randomX" y="0" z="randomZ" angle="0" age="1" />
  </event>
  <event>
    <if_variable name="missionSelected" comparator="EQUALS" value="7" />
    <if_variable name="missionPhase" comparator="EQUALS" value="4" />
    <if_variable name="minesValue" comparator="GREATER" value="0" />
    <if_variable name="missionType" comparator="EQUALS" value="1" />
    <if_variable name="minesDeg" comparator="GREATER_EQUAL" value="90" />
    <if_variable name="minesDeg" comparator="LESS" value="135" />
    <if_not_exists name="WRK" />
    <set_variable name="randomZ" randomIntLow="-minesDist/10" randomIntHigh="minesDist/10" />
    <set_variable name="randomX" value="minesX*2-minesDist*0.7+randomZ" />
    <set_variable name="randomZ" value="minesZ*2+minesDist*0.7+randomZ" />
    <create name="WRK" type="monster" monsterType="8" x="randomX" y="0" z="randomZ" angle="0" age="1" />
  </event>
  <event>
    <if_variable name="missionSelected" comparator="EQUALS" value="7" />
    <if_variable name="missionPhase" comparator="EQUALS" value="4" />
    <if_variable name="minesValue" comparator="GREATER" value="0" />
    <if_variable name="missionType" comparator="EQUALS" value="1" />
    <if_variable name="minesDeg" comparator="GREATER_EQUAL" value="135" />
    <if_variable name="minesDeg" comparator="LESS" value="180" />
    <if_not_exists name="WRK" />
    <set_variable name="randomX" randomIntLow="-minesDist/10" randomIntHigh="minesDist/10" />
    <set_variable name="randomX" value="minesX*2+randomX" />
    <set_variable name="randomZ" value="minesZ*2+minesDist" />
    <create name="WRK" type="monster" monsterType="8" x="randomX" y="0" z="randomZ" angle="0" age="1" />
  </event>
  <event>
    <if_variable name="missionSelected" comparator="EQUALS" value="7" />
    <if_variable name="missionPhase" comparator="EQUALS" value="4" />
    <if_variable name="minesValue" comparator="GREATER" value="0" />
    <if_variable name="missionType" comparator="EQUALS" value="1" />
    <if_variable name="minesDeg" comparator="GREATER_EQUAL" value="180" />
    <if_variable name="minesDeg" comparator="LESS" value="225" />
    <if_not_exists name="WRK" />
    <set_variable name="randomZ" randomIntLow="-minesDist/10" randomIntHigh="minesDist/10" />
    <set_variable name="randomX" value="minesX*2+minesDist*0.7+randomZ" />
    <set_variable name="randomZ" value="minesZ*2+minesDist*0.7-randomZ" />
    <create name="WRK" type="monster" monsterType="8" x="randomX" y="0" z="randomZ" angle="0" age="1" />
  </event>
  <event>
    <if_variable name="missionSelected" comparator="EQUALS" value="7" />
    <if_variable name="missionPhase" comparator="EQUALS" value="4" />
    <if_variable name="minesValue" comparator="GREATER" value="0" />
    <if_variable name="missionType" comparator="EQUALS" value="1" />
    <if_variable name="minesDeg" comparator="GREATER_EQUAL" value="255" />
    <if_variable name="minesDeg" comparator="LESS" value="270" />
    <if_not_exists name="WRK" />
    <set_variable name="randomZ" randomIntLow="-minesDist/10" randomIntHigh="minesDist/10" />
    <set_variable name="randomX" value="minesX*2+minesDist" />
    <set_variable name="randomZ" value="minesZ*2+randomZ" />
    <create name="WRK" type="monster" monsterType="8" x="randomX" y="0" z="randomZ" angle="0" age="1" />
  </event>
  <event>
    <if_variable name="missionSelected" comparator="EQUALS" value="7" />
    <if_variable name="missionPhase" comparator="EQUALS" value="4" />
    <if_variable name="minesValue" comparator="GREATER" value="0" />
    <if_variable name="missionType" comparator="EQUALS" value="1" />
    <if_variable name="minesDeg" comparator="GREATER_EQUAL" value="270" />
    <if_variable name="minesDeg" comparator="LESS" value="315" />
    <if_not_exists name="WRK" />
    <set_variable name="randomZ" randomIntLow="-minesDist/10" randomIntHigh="minesDist/10" />
    <set_variable name="randomX" value="minesX*2+minesDist*0.7-randomZ" />
    <set_variable name="randomZ" value="minesZ*2-minesDist*0.7-randomZ" />
    <create name="WRK" type="monster" monsterType="8" x="randomX" y="0" z="randomZ" angle="0" age="1" />
  </event>
  <event>
    <if_variable name="missionSelected" comparator="EQUALS" value="7" />
    <if_variable name="missionPhase" comparator="EQUALS" value="4" />
    <if_variable name="minesValue" comparator="GREATER" value="0" />
    <if_variable name="missionType" comparator="EQUALS" value="1" />
    <if_variable name="minesDeg" comparator="GREATER_EQUAL" value="315" />
    <if_variable name="minesDeg" comparator="LESS" value="360" />
    <if_not_exists name="WRK" />
    <set_variable name="randomX" randomIntLow="-minesDist/10" randomIntHigh="minesDist/10" />
    <set_variable name="randomX" value="minesX*2-randomX" />
    <set_variable name="randomZ" value="minesZ*2-minesDist" />
    <create name="WRK" type="monster" monsterType="8" x="randomX" y="0" z="randomZ" angle="0" age="1" />
  </event>


Note that since typically generated minefields are located by degree and distance from the origin (which in this case was the center of the sector) I couldn't just drop the wreck at the X and Y location of the field. If you were locating an object by X and Y coordinate and trying to determine the degree, you would essentially have to reverse the test I used above. Basically, check if your x or y coordinate is less than or greater than the center of the sector, and then see if the absolute value of x or y is within 0.3 of the other value. (i.e, abs(x-y) < 0.3*max(x,y), at which time the object is 45 degrees off the north/sound axis, not 90 degrees. Note the square root of 2 is around 0.7, which is where that number comes from in the code above)

If it were possible to calculate sines and cosines, you could calculate the exact angle. As it is, you could continue to break down the arc into 22.5 degree arcs, 30 degree arcs, 15 degree arcs, or even 5 degree arcs, as long as you're willing to add all those events to check which arc the object is in. 45 degrees is probably the easiest and yet will still get you in the general vicinity.

Another possibility is that you could constantly calculate when your object moves into another arc or a previous arc in each cycle. This is basically the same as tracking the object's x and y location by testing if x is greater than or less than your variable and updating it accordingly. As with location, the resolution of your arcs will determine how many events it will take to calculate, and how close to the actual object your "guess" will be.
Richard

Registered:
Posts: 126
Reply with quote  #3 
Thanks, ryleyra!

Anyway I think I'm going to post this in the development section of the forum, bearing could be a property of an object.
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.