Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 [2]

Author Topic: LeadVector  (Read 7087 times)

MesoTroniK

  • Admiral
  • *****
  • Posts: 1731
  • I am going to destroy your ships
    • View Profile
Re: LeadVector
« Reply #15 on: May 08, 2014, 04:51:44 PM »

(Re: vanilla missiles - they do use target leading, they're intentionally not great at it, and the leading can be improved via skills. Dodging missiles is fun. They're also slightly harder to shoot down with PD.)

It seems to me just by observing that vanilla missiles at first set up a lead intercept course, and when they are close to the target they swap to a simple tail chase trajectory.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: LeadVector
« Reply #16 on: May 08, 2014, 06:35:56 PM »

@dmaiski: All I can say is 1) from a pure math point of view, what you're saying isn't correct (if the ship can accelerate faster than the missile, it can get out of the way, and further, the missile is at a bit of a disadvantage because it's applying thrust towards the intercept point, rather than in the direction that the ship is accelerating in, so only part of its acceleration is competing against the ship's) and 2) how it actually works in the game bears out what I'm saying. Refer to what I mentioned earlier re: Pilums, orbiting behavior, etc. I have a feeling you may have skipped over that.


It seems to me just by observing that vanilla missiles at first set up a lead intercept course, and when they are close to the target they swap to a simple tail chase trajectory.

I don't actually remember right now, but I don't think they switch algorithms. I think for stuff like Pilums, they just don't have the engine to keep up with frigates when they're close and the relative movement is more pronounced, so it looks more like a tail chase because of that. Could be wrong, though - not looking at the code right now. I'm definitely remembering doing something like what you're saying, but that may have just been the heatseeker AI.

All of this does give me an idea for adjusting something specific in the algorithm... hmm. See, the thing is that heading directly for the intercept point is actually wrong. You want to head in the direction that makes your velocity point towards the intercept point, and that's not necessarily the same thing - basically, you want to compensate for your current velocity, instead of relying on the top-speed-capping algorithm to eventually cancel out any factors not in the direction you're accelerating in. Stay tuned :) Never mind, the vanilla AI already takes this into account...
« Last Edit: May 08, 2014, 10:40:44 PM by Alex »
Logged

MesoTroniK

  • Admiral
  • *****
  • Posts: 1731
  • I am going to destroy your ships
    • View Profile
Re: LeadVector
« Reply #17 on: May 08, 2014, 08:22:51 PM »

This shows pretty clearly in my opinion how the vanilla missile AI starts with lead intercept and then swaps to tail chase at the last second.

Also showed some modded ones that use a pure tail chase profile, ones that spread out and then try to converge, and ones that fly drunkenly on purpose for some reason.

Dark.Revenant

  • Admiral
  • *****
  • Posts: 2806
    • View Profile
    • Sc2Mafia
Re: LeadVector
« Reply #18 on: May 08, 2014, 09:20:20 PM »

Did a few of the things you said, and now Blackrock Driveyard darts are completely impossible to evade.  Great.

http://pastebin.com/hNVDQnvJ
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: LeadVector
« Reply #19 on: May 08, 2014, 10:06:08 PM »

@MesoTroniK: Hmm. Looked at the AI, it doesn't change the targeting algorithm, but may decide to slow down/accelerate in part depending on how far from the target it is.


Did a few of the things you said, and now Blackrock Driveyard darts are completely impossible to evade.  Great.

http://pastebin.com/hNVDQnvJ

Cool! Oh, hey, just noticed - you're cheating; missiles aren't supposed to strafe :) (Alright, let's say they've got vectored thrust.)

(Extremely minor side note- this line here:
float scalar = distance / missile.getVelocity().length();
May want to check to make sure there's no divide by zero.)
Logged

MesoTroniK

  • Admiral
  • *****
  • Posts: 1731
  • I am going to destroy your ships
    • View Profile
Re: LeadVector
« Reply #20 on: May 08, 2014, 10:10:56 PM »

Very interesting, thank you for looking into that Alex.

Even though it is not changing algorithms, in effect it is reducing the accuracy in a manner that looks similar to tail chase right before it hits the target.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24118
    • View Profile
Re: LeadVector
« Reply #21 on: May 08, 2014, 10:20:37 PM »

Yeah... I think it's what I said earlier - the closer the missile gets to the target, the harder it has to work to stay on target. And since most vanilla missiles have fairly underwhelming engine stats...
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: LeadVector
« Reply #22 on: May 09, 2014, 12:12:45 AM »

IRL anti-fighter missiles don't always have a fuse set to impact on detonate, but instead act a lot like the sabot, they get close then release their load. http://youtu.be/bKsreHMX3xE?t=2m22s
Now when it's a missile vs an actual naval ship...well...doesn't really matter at all, it's not like a ship could ever outpace a harpoon missile. For better handling of missiles at terminal stages I'd look at getting it lined up then firing the warhead at higher velocities. You'd do less damage I guess, but get a greater frequency of impacts.
Logged

dmaiski

  • Captain
  • ****
  • Posts: 422
  • resistance is futile
    • View Profile
Re: LeadVector
« Reply #23 on: May 09, 2014, 05:59:05 AM »

@Alex

using a slightly modified script:
Spoiler
Code: java
    //same as Lead vector, but returns lead time
    public static float LeadTime(Vector2f TLoc, Vector2f TVel, Vector2f MLoc, Vector2f MVel)
    {
        //get missiles speed
        float MSpeed = (float)Math.sqrt(MVel.lengthSquared());

        //separate out the vectors
        float Tx = TLoc.getX();
        float Ty = TLoc.getY();
        float Mx = MLoc.getX();
        float My = MLoc.getY();

        float TVx = TVel.getX();
        float TVy = TVel.getY();

        //subtract position vectors
        float x1 = Tx - Mx;
        float y1 = Ty - My;

        //quadratic fun
        float h1 = TVx*TVx + TVy*TVy - MSpeed*MSpeed;
        if (h1==0)
        {
            h1= (float) .0001;
        }

        float minusMHalf = -(x1*TVx + y1*TVy)/h1;  // h2/h1

        float discriminant = minusMHalf * minusMHalf - (x1*x1 + y1*y1)/h1; // (h2/h1)^2-h3/h1 (ie D)

        //can they intersect?
        if (discriminant < 0)
        {
            return 0;
        }


        double root = Math.sqrt(discriminant);

        double t1 = minusMHalf + root;
        double t2 = minusMHalf - root;

        double tMin = Math.min(t1, t2);
        double tMax = Math.max(t1, t2);
        //which of the 2 is smaller
        double time = tMin > 0 ? tMin : tMax;

        //can return -ve time (this is less then useful)
        if (time < 0)
        {
            return 0;
        }

        //calculate vector
        return (float)time;
    }
[close]

you can get the time component

to get a normal intercept point you would use
velocity(vector) * time

to get accelerating object intercept you would use
velocity(vector) * time +  acceleration(vector) * 0.5f *time

or even more fancy (if you want to be super accurate)
Spoiler
(MaxSpeed-CurSpeed)/acceleration = ATime

if(ATime<time)  //for cases when a ship can accelerate to max speed before missile hits
velocity(vector) * ATime +  acceleration(vector) * 0.5f *ATime + Norm.acceleration(vector) * MaxSpeed * (time- ATime)
else           //for cases when it cant
velocity(vector) * time + acceleration(vector) * 0.5f *Time = LeadLoc

then for super pointless levels of accuracy, perform a recursive calculation:
(warning : using recursive calculations is expencive... and kinda pointless unless you want missiles to be ably to track weaving talons or somesuch)
Spoiler
norm.LeadLoc * TSpeed = R1

LeadTime(Tloc, R1, MLoc, MVel) * norm.LeadLoc = LeadLoc
[close]

LeadLoc + TLoc = intercept coordinates

unless the ship actively changes direction this does not need to chage at all
so you can use a check weather the ship changed its end directional vector, and only recalculate if it has

[close]

there acceleration issue solved :P
(:P im glad my equasion gets time instead of angle, time is so much more usefull :P)

on missile strafing:
Spoiler
its not really required, my AIs can be set to no-strafe mode quite easily with no impact on performance

all that needs to be done is you calculate curent vector, the vector adjustment needed to be on target,
then calculate vector direction you need to go to perform the adjustment
then you turn the missile into that vector direction

...and presto, no need to strafe: the missile does look like it is flying crooked though
(thats why strafe is perfered, it simply looks better)

sidenote: VectorDirection is a normalized vector (i use them almost exclusively when writing AI)
i substitute these for all angles since the bulk of the AI prefers vector calculations instead of angles, makes coding faster
[close]
« Last Edit: May 09, 2014, 04:19:36 PM by dmaiski »
Logged
BISO
(WIP) lots of shiny new weapons ( :-[ i have more weapons then sprites :-[ )

i got a cat pad
its like a mouse pad but better!
Pages: 1 [2]