Y-Position Stabilization (complex)


Y-POSITION STABILIZATION (complex, looks better)

by Hissatsu

 

This is a code snippet that gradually moves player ship back to the 0 on the Y axis, which is useful if your mission includes asteroids which player can collide with.

This one is more complex than one by Vorus, but it looks better, because player ship is gradually moved towards 0, not instantly reset back to 0.

 

<event >
    <if_variable name="general_init" comparator="NOT" value="1.0" />
    <set_variable name="general_init" value="1.0" />
    <!---->
    <set_timer name="keep_artemis_on_y0_plane" seconds="1" />
  </event>
  <event>
    <if_object_property property="positionY" name="Artemis" comparator="GREATER" value="0.0" />
    <if_timer_finished name="keep_artemis_on_y0_plane" />
    <addto_object_property value="-0.05" property="positionY" name="Artemis" />
    <set_timer name="keep_artemis_on_y0_plane" seconds="1" />
  </event>
  <event >
    <if_object_property property="positionY" name="Artemis" comparator="LESS" value="0.0" />
    <if_timer_finished name="keep_artemis_on_y0_plane" />
    <addto_object_property value="0.05" property="positionY" name="Artemis" />
    <set_timer name="keep_artemis_on_y0_plane" seconds="1" />
  </event>
  <event>
    <if_object_property property="positionY" name="Artemis" comparator="GREATER_EQUAL" value="-0.05" />
    <if_object_property property="positionY" name="Artemis" comparator="LESS_EQUAL" value="0.05" />
    <if_object_property property="positionY" name="Artemis" comparator="NOT" value="0.0" />
    <set_object_property property="positionY" value="0" name="Artemis" />
  </event>

 

First event initializes the stabilization code.

Second and third events move Artemis a bit closer to 0 on Y axis each second.

Fourth event will take it exactly to 0 on Y axis when its almost there.