Author Topic: Limit of an imaginary axis  (Read 2177 times)

0 Members and 1 Guest are viewing this topic.

Offline coffeesoft

  • 28
  • Bip Bip
Limit of an imaginary axis
Hi.

I wanted to ask if anyone knows how to tell the pilots that not exceeding an imaginary axis or plane just to make a surface mission using a big POF model as surface.

Pilots are crashing everytime with the surface if the objetives are too close, i know the engine was no made for this kind of mission but maybe someone knows a trick or a script.

Many thanks  :)

 

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Re: Limit of an imaginary axis
It's certainly possible to script that, although I don't really have a ready-to-use script for that. Here's a modified and trimmed-down version of a similar script I have though, which can at least serve as a starting point:

Code: [Select]
#Conditional Hooks

$Application: FS2_Open

$On Game Init: [
   
    ai_ship_meta = {}

    avoid_ground = function(ship, altitude)
        ship_pos = ship.Position
        ship_forward_pos = ship_pos + ship.Orientation:unrotateVector(ba.createVector(0, 0, 400))
        ship_down_pos = ship_pos + ship.Orientation:unrotateVector(ba.createVector(0, -400, 0))
        ship_up_pos = ship_pos + ship.Orientation:unrotateVector(ba.createVector(0, 400, 0))
        ship_left_pos = ship_pos + ship.Orientation:unrotateVector(ba.createVector(-400, 0, 0))
        ship_right_pos = ship_pos + ship.Orientation:unrotateVector(ba.createVector(400, 0, 0))

        if ship_forward_pos["y"] < altitude or ship_pos["y"] < altitude then
            if ai_ship_meta[ship.Name] == nil or not ai_ship_meta[ship.Name].evading_ground then
                ai_ship_meta[ship.Name] = { evading_ground = true, direction = "nowhere" }
               
                if ship_up_pos["y"] > altitude then
                    ship:doManeuver(1000, 0, -1.0, 0, true, 0, 0, 1.0, false)
                    ai_ship_meta[ship.Name].direction = "up"
                elseif ship_down_pos["y"] > altitude then
                    ship:doManeuver(1000, 0, 1.0, 0, true, 0, 0, 1.0, false)
                    ai_ship_meta[ship.Name].direction = "down"
                elseif ship_left_pos["y"] > altitude then
                    ship:doManeuver(1000, -1.0, 0, 0, true, 0, 0, 1.0, false)
                    ai_ship_meta[ship.Name].direction = "left"
                elseif ship_right_pos["y"] > altitude then
                    ship:doManeuver(1000, 1.0, 0, 0, true, 0, 0, 1.0, false)
                    ai_ship_meta[ship.Name].direction = "right"
                else
                    ai_ship_meta[ship.Name].direction = "nowhere"
                end
            end

            return true
        else
            if ai_ship_meta[ship.Name] == nil then
                ai_ship_meta[ship.Name] = { evading_ground = false, direction = "nowhere" }
            else
                if ai_ship_meta[ship.Name].evading_ground then
                    ai_ship_meta[ship.Name] = { evading_ground = false, direction = "nowhere" }
                   
                    ship:doManeuver(4000, 0, 0, 0, true, 0, 0, 1.0, true)
                end
            end
           
            return false
        end
    end

]

#End

You'd just need to call the avoid_ground() function on all AI ships every frame (or maybe just once per second) in an $On Frame hook or from a mission event and hope it actually works as intended (I might have messed up something when adapting it to this purpose).

The ships might also end up doing a funny up-down-up-down-up-down bobbing motion close to the ground if they for some reason really want to go below the given altitude, but you can do something like change their current goal to remedy that. You'll also want to change the magic value of 400; the avoidance behavior kicks in when the distance along the ship's forward vector to the given altitude becomes less than that value.

 

Offline coffeesoft

  • 28
  • Bip Bip
Re: Limit of an imaginary axis
Many thanks, is a nice starting point  ;)

I don´t know how to program so i cannot promise many changes on the script, but for sure i will test it and try to make all things possible.
In a quick first check the ships has better behavior ....   :nod:

 

Offline coffeesoft

  • 28
  • Bip Bip
Re: Limit of an imaginary axis
After some testing the script works good as it is, just keeping some security distance with the surface.

You do not know how grateful I am  :), no more pilots crashing everytime...

 

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Re: Limit of an imaginary axis
I guess I'm mildly surprised it worked as it is, but good if it does.

From where and how often did you end up calling it, though?

 

Offline coffeesoft

  • 28
  • Bip Bip
Re: Limit of an imaginary axis
I´m puting down the surface at -700m from 0 and the fighters collide less ( with the script ),ok,  sometimes are crashing but they will look with a different behavior, and appears to remain more upward, at least with this mission.


 

Offline Herra Tohtori

  • The Academic
  • 211
  • Bad command or file name
Re: Limit of an imaginary axis
And here I was thinking this thread was about using complex numbers in FREDding...
There are three things that last forever: Abort, Retry, Fail - and the greatest of these is Fail.

  
Re: Limit of an imaginary axis
Yeah, me too.