1. This forum is obsolete and read-only. Feel free to contact us at support.keenswh.com

Long range Lock-On concept, no turrets.

Discussion in 'Programming (In-game)' started by Pennywise, Oct 10, 2015.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    Hello, space engineers!
    I want to share with you a concept of long-range lock-on.
    It's described in this short video.

    I will add script later and transfer this thread to "ingame scripting" tree.
    But, since this feature can be of interest to all players, not only involved in ingame programming, and the possibility of lock-on weapons was discussed many times, let it hang a couple of days in general discussion.

    UPD#1 Workshop item:
    --------------------------
    First long-range homing missile based on this concept is uploaded to workshop:
    https://steamcommunity.com/sharedfiles/filedetails/?id=535178926
    my thread in community creations:
    https://forums.keenswh.com/threads/p...-last-item-long-range-homing-missile.7369856/
    9000m long shot of cargo ship:

    Shoting ships on a backyard of my space base with some advices on using these missiles:

    Feedbacks, reports, suggestions are welcome.

    UPD#2, How it works:
    -------------------------
    Missile RemoteControl continuosly checks 5 vectors:

    1. FORWARD. It is 1m wide.
    This vector is pointed direct to target, if missile haven't lost its lock.
    It is used to check, target is still there and to measure distance. For distance measurement i check this vector from 10 to 3 times in a cycle to get distance.
    2. 4 "locking vectors". These vectors are 50 m wide, They are directed to points 50 m UP, DOWN, LEFT and RIGHT from FORWARD vector pointing.
    [​IMG]

    Let's look at LEFT and RIGHT pair of vectors.
    [​IMG]

    When they are checked with GetFreeDestination(), function returns free vectors for each one of them (original vectors are red, free vectors are green).
    And we can measure angle between original and free vectors for each side of target (A and B).
    If FORWARD points in geometrical center of target projection, angles A and B should be equal.
    If A > B, then FORWARD is pointing closer to right edge of target.
    We can use difference between A and B as an input signal for missile gyroscope Yaw axis.
    I take this value: (B-A)/(A+B) / distance to trarget. You can add some multipliers to make gyro more or less responsive.
    The same we do with UP and DOWN vectors. And use difference btw them as an input signal for gyroscope Pitch.
    Roll can be set to 0, or some value, if you want missile to roll around it's Z while upproaching target.
    My missile has all lateral thrusters pointing to one side, so i'm using roll for velocity dampening.
    Which is a cool thing, because i have 4x more thrust dampening my escaping velocity while turning.
    So, it's less chance to miss the target in last moment.

    That's how it works.

    Possible improvements:
    1. RemoteControl can check any direction, so we dont really have to point target with our nose.
    Actually, we can keep target in lock, while missile goes not to target directly, but to interception point.
    Also it can maneuver free to dodge turrets. So we will build much less expensive homing missiles based on small grid.

    Where it can be used:
    1. Homing missiles
    2. Ballistic calculators
    3. Orbiting drones
    4. Space scanners. We can scan any direction and analyse shapes, signatures, probably classify scanned objects.

    UPD#3 Script
    -----------------------------
    This is the script itself. It's far not perfect, there are much unneccessary normalizings, and i guess i can initialize less vectors.
    It only shows idea:

    Code:
    void	LockOn()  
       {  
    	 var pivotBlock = GridTerminalSystem.GetBlockWithName(ShipName+"RemCon") as IMyTerminalBlock;  
    	 Vector3D V3Dcenter = pivotBlock.GetPosition();  
    	 Vector3D V3Dfow = pivotBlock.WorldMatrix.Forward;  
      Vector3D V3Dup = pivotBlock.WorldMatrix.Up;  
      Vector3D V3Dleft = pivotBlock.WorldMatrix.Left;  
      Vector3D V3Ddown;  
      Vector3D V3Dright;  
    	 Vector3D V3DMyVelocity=V3Dcenter-V3DPrevCenter;  
    	  Vector3D V3Dfree = (pivotBlock as IMyRemoteControl).GetFreeDestination(V3Dfow + V3Dcenter,Z1,20);  
    	  if ((V3Dfree!=V3Dfow+ V3Dcenter)&&(Z1>1000))  
    	  {  
    		for (int x=0;x<Accuracy;x++)  
    		{  
    		  Z=Z0+((Z1-Z0)/2);  
    		  V3Dfree = (pivotBlock as IMyRemoteControl).GetFreeDestination(V3Dfow + V3Dcenter,Z,20);  
    		  if (V3Dfree!=V3Dfow+ V3Dcenter)  
    			Z1=Z;  
    		  else  
    			Z0=Z;  
    		}  
    	   Z1=Z+50;  
    	   Z0=Z-50;  
    	   Accuracy=3;  
    	 }	
    	  else  
    	  {  
    		Z=0;  
    		Z1=MaxDist;  
    		Z0=0;	  
    	   Accuracy=10;		
    	}	
      
    	 double AlphaUp;  
    	 double AlphaDown;  
    	 double AlphaLeft;  
    	 double AlphaRight;  
      
    	 V3Dup=Vector3D.Transform(Vector3D.Normalize(new Vector3D(0,Base,-Z1)),pivotBlock.WorldMatrix);  
    	 V3Ddown=Vector3D.Transform(Vector3D.Normalize(new Vector3D(0,-Base,-Z1)),pivotBlock.WorldMatrix);  
    	 V3Dright=Vector3D.Transform(Vector3D.Normalize(new Vector3D(Base,0,-Z1)),pivotBlock.WorldMatrix);  
    	 V3Dleft=Vector3D.Transform(Vector3D.Normalize(new Vector3D(-Base,0,-Z1)),pivotBlock.WorldMatrix);  
    	  
    	 Vector3D V3DfreeUp = Vector3D.Normalize((pivotBlock as IMyRemoteControl).GetFreeDestination(V3Dup,Z1,Base)-V3Dcenter);  
    	 Vector3D V3DfreeDown = Vector3D.Normalize((pivotBlock as IMyRemoteControl).GetFreeDestination(V3Ddown,Z1,Base)-V3Dcenter);  
    	 Vector3D V3DfreeLeft = Vector3D.Normalize((pivotBlock as IMyRemoteControl).GetFreeDestination(V3Dleft,Z1,Base)-V3Dcenter);  
    	 Vector3D V3DfreeRight = Vector3D.Normalize((pivotBlock as IMyRemoteControl).GetFreeDestination(V3Dright,Z1,Base)-V3Dcenter);	  
    	  
    	 AlphaUp=Math.Acos(Vector3D.Dot(V3Dup-V3Dcenter, V3DfreeUp));  
    	 AlphaDown=Math.Acos(Vector3D.Dot(V3Ddown-V3Dcenter, V3DfreeDown));  
    	 AlphaLeft=Math.Acos(Vector3D.Dot(V3Dleft-V3Dcenter, V3DfreeLeft));  
    	 AlphaRight=Math.Acos(Vector3D.Dot(V3Dright-V3Dcenter, V3DfreeRight));  
    	  
    	 double BetaUp=(AlphaUp-AlphaDown)/(AlphaUp+AlphaDown);  
    	 double BetaRight=(AlphaRight-AlphaLeft)/(AlphaRight+AlphaLeft);	
    	 if (double.IsNaN(BetaUp))  
    	 BetaUp=0;  
    	 if (double.IsNaN(BetaRight))  
    	 BetaRight=0;	  
    	 if ((Z>500) && (FireMode!="Stop"))  
    	 {  
    	   TurnGroup(ShipName+"SpotLight","On");  
    	   TurnGroup(ShipName+"Sound","On");  
    	 }  
    	 else  
    	 {  
    	   TurnGroup(ShipName+"SpotLight","Off");  
    	   TurnGroup(ShipName+"Sound","Off");	  
    	 }  
    	 if (FireMode=="Launch")  
    	 {  
    	   TurnGroup(ShipName+"Thr","On");	   
    	   TurnGroup(ShipName+"Merge", "Off");	   
    	   setThrustGroupLevel(ShipName+"ThrF",2304000);  
    	   if(TickCount > 180)  
    		 setGyroOverride(ShipName+"Gyroscope",true);  
    	 }  
    	 double AlphaVel=Vector3D.Dot(Vector3D.Normalize(pivotBlock.WorldMatrix.Forward),Vector3D.Normalize(V3DMyVelocity));  
    	 Vector3D V3DampNorm=Vector3D.Normalize(Vector3D.Normalize(V3DMyVelocity)/AlphaVel-Vector3D.Normalize(pivotBlock.WorldMatrix.Forward));  
    	 double Roll=Math.Acos(Vector3D.Dot(Vector3D.Normalize(pivotBlock.WorldMatrix.Up),V3DampNorm));  
    	 if ((Vector3D.Normalize(pivotBlock.WorldMatrix.Left)-V3DampNorm).Length()>2/(Math.Sqrt(2)))  
    	   Roll=-Roll;  
    	
    	 if (FireMode=="Launch")  
    	 {	   
    	   int Koeff=10000/Z1; 
    	   if (Koeff>10) 
    		 Koeff=10;
    		
    	 setGyroGroupLevel(ShipName+"Gyroscope", "Pitch", BetaUp*Koeff,1f);  
    	 setGyroGroupLevel(ShipName+"Gyroscope", "Yaw", BetaRight*Koeff,1f);  
    	 if(TickCount > 300)  
    	   setGyroGroupLevel(ShipName+"Gyroscope", "Roll", -Roll*3,1f);	  
    	 }  
    	  
    	 Echo("FireMode: "+FireMode+"\nDistance: "+ Z.ToString()+"\n UP: "+BetaUp.ToString()+"\n RT: "+BetaRight.ToString());  
    	 V3DPrevCenter=V3Dcenter;  
    	 if (TickCount>20000)  
    	   FireMode="Stop";  
    	 if (FireMode!="Stop")  
    	   Timer.GetActionWithName("TriggerNow").Apply(Timer);	  
    	 else  
    	   Timer.GetActionWithName("Stop").Apply(Timer);  
    	 }
      
    UPD#4 A little experiment with GetFreeDestination(). It checks not intersection with real object, but intersection with its bounding sphere.


    UPD#5 How GetFreeDestination() really works. Last version of lock on algorithm.

    Here is the final version of target lock function.
    It's based on analysing of source code of GetFreeDestination().
    I guess, I came to the same thing as Gurgl's algorithm. But now, I really understand, how it works.

    At first, let's look into Keen's source of GetFreeDestination():

    Basically, it does the following (pic 1):

    [​IMG]

    1. Find initial ray's "RO" intersection point "O" with bounding sphere of target "T".
    2. Find radius from target center to intersection point "TO"
    3. Find rejection "RO" of "TO" ---> "OF", so "OF" is a line, touching bounding sphere in intersection point "O".
    Note, "OF" lies in the plane "RTO" (remote control, target center, intersection point), cause it's Reject(RO, TO).
    4. Set length of "OF" to max value of (TO/2, 20). So, if bounding sphere of target has radius < 40m, then OF is 20m long, otherwise it's half-radius long.
    5. Point "F" is the point, returned as free destination by GetFreeDestination() function.

    Ok, now we know how GFD() works. I've not mentioned CheckRadius var, it affects free point position too, but I use 0.01m check radius, so i neglect it.

    Here is my last lock-on function. I think, it uses very similar algorithm to one, posted by Gurgl above.

    It does the following (pic 2):
    1. Check initial vector "RO1" and find first free point "F1"
    2. Set length of "RO1" = Length of "RF1"
    3. Find 1m long vector O2 = (F1-O1).Normalize(). So, now we can add this vector to O1 to get points 1m and 2m closer to first free point F1. And use them as check points to get 2 more free points.
    4. Check 2 additional points "O1+O2" and "O1+O2*2" and get F2 and F3 points.
    5. The radius "TO" of target's bounding sphere has always the same length. "OF" has always the same lenght too, it's either 1/2 radius or 20m(if target's radius is smaller then 40m). Angle "TOF" is always 90 grad, so we can conclude, that lengths of "TF1", "TF2", "TF3" are equal. In addition to, all points: R, T, F1, F2, F3 belong to one plane. This means, F1, F2, F3 points belong to circumference with the center in "T" point, which is a center of target's bounding sphere.
    6. Ok, now we find a circle center and radius by 3 points (F1, F2, F3). That's all.

    This func is much more stable and precize. It provides very reliable targets speed measurement, because lock doesn't jump from point to point as before. In addition to, it can lock small grid ships as well as large ones.
     
    Last edited: Dec 6, 2015
    • Like Like x 18
    • Informative Informative x 3
  2. Baalrog

    Baalrog Apprentice Engineer

    Messages:
    152
    Impressive!
     
  3. Klaern

    Klaern Apprentice Engineer

    Messages:
    296
    First off, awesome work, again.

    This does seem like something that defies the normal ability within the game though. Sensors being what we typically have to detect objects in space, this offers essentially the same functionality without the limitation of needing sensors, or sensors' short range. Based on how you're using it, it seems it would even be possible to use GetFreeDestination() for long range scanning and locating objects. It almost certainly wouldn't be as fast of a detection as sensors, but with a much higher range (infinite?) this seems OP.
     
    • Like Like x 1
  4. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    Thank you!
    Here is a video of first homing missile using this principe:

    I'll make it ready for workshop soon.
     
    • Like Like x 3
  5. Stiletto

    Stiletto Apprentice Engineer

    Messages:
    381
    That's a rather lovely script with a lot of potential and uses!

    Great work!

    Space Pirates are greedy and only see booty wherever they go. They're also avid haters of having to purchase things and would rather take it from you, after 'gifting' you with some ammunition.
     
  6. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    This function can be used to detect and even shape any physical objects in a long distance. I've tested it on 30 000m, works well. It can be called each tick, but it's very CPU-expensive, so we probably wont be able to make huge scanning arrays in multiplayer without making all other players swearing and hating us. But for my LockOn i'm calling this func 7-10 times per tick, UPS is still 60. For 100 calls per tick problems start showing themself.
     
  7. Klaern

    Klaern Apprentice Engineer

    Messages:
    296
    That's awesome. Even for a slower sweep of the sky, which would assumedly be less CPU-expensive, this could be used to detect and record the location of asteroids when you settle a new area. Then coordinates could be used to auto-deploy probes to locate ore, or drones to mine it.

    Or it could be used to keep track of mines in a minefield. Detect when one goes missing, and deploy a replacement.

    This is great, so many possible uses. I wonder if Keen realized that this could be used as long range sensors like this with just the PB, or if this is something they'll see as a mistake and "fix".
     
  8. KalTauri

    KalTauri Trainee Engineer

    Messages:
    46
    What block is the detection based on? I am at work so can't listen to audio for several more hours.

    And does it require constant contact(pointing) to maintain its ability to sense? Or do you have a handle as soon you make contact and can use that to stay locked?
     
  9. estile606

    estile606 Trainee Engineer

    Messages:
    70
    I can see a good use for this when planets come out: having a ship with a large array of solar panels that flies around the planet to keep in view of the sun, and charges batteries, and have automated drones that track this ship and fly to it no matter what side of the planet it is on, which take the charged batteries to various locations on the planet and bring up empty ones for recharging
     
  10. Klaern

    Klaern Apprentice Engineer

    Messages:
    296
    It's based on an autopilot method on the RemoteControl block.


    I almost have a script for the non-planet version of that finished via positions passed by Laser Antenna. My solar array is mobile, but my station that uses the batteries is not mobile. For planets, it'd need a LA network to achieve the same thing since the planet could block LOS. It'd make communication slower, but it's still completely possible with LAs.

    I don't think Pennywise's method would require LOS though, so that's interesting (and another reason it's OP). Assuming the solar array isn't moving too quickly (I don't think it'd need to) the script wouldn't need to run too fast so it wouldn't cause lag either. I'm pretty sure it'd be a reasonably solid solution for location tracking without LOS. Then for getting docking coordinates and the approach vector, LAs could still be used from solar array to drone. In my script, I stop the solar array from moving while the docking procedure is under way (without instant cross-grid communication, I'm not sure it's possible to dock to a (variably) moving target, maybe with sensors?).

    For planets, I was actually thinking of using a space elevator type solution for powering the planetary grid from space. Have the docks for the grid up at the top of the elevator, and drones run from there to the solar array. I'm assuming it'd cost too much power to escape the gravity of a planet though, to make drones from planet to space moving batteries feasible (we'll see though).

    Realistically, having a large solar array on the surface of the planet and just a bunch of batteries to store power to make it through nights is probably the easier and more efficient solution. But for a non-day/night cycle world, having solar up in space and living on the dark side of a planet could be an interesting challenge.
     
    Last edited: Oct 13, 2015
  11. RageMasterUK

    RageMasterUK Apprentice Engineer

    Messages:
    201
    Nice one Pennywise... enjoyed learning through your video, pirates better watch out.
     
  12. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    Item uploaded to workshop:
    https://steamcommunity.com/sharedfiles/filedetails/?id=535178926
    my thread in community creations:
    https://forums.keenswh.com/threads/p...-last-item-long-range-homing-missile.7369856/

    Feedbacks, reports, suggestions are welcome.

    There are still many things to improve.
    I will add some detailed explanation of an idea and how you can use it for you own creations: missiles, support drones (like taklers, orbiters, bombers), ballistic calculators (if we can continuosly log vector and distance to moving target like npc cargo ship, then after some interpolation we can get its velocity vector and try to shoot it from grav canon or catapult).
     
    Last edited: Oct 15, 2015
    • Like Like x 1
  13. Sinbad

    Sinbad Senior Engineer

    Messages:
    2,788
    so, what does GetFreeDestination do? and how does that translate into getting the objects position? I don't have the most recent docs with me so I can't look it up myself.
     
  14. Warstrider

    Warstrider Trainee Engineer

    Messages:
    47
    Have my subscription!

    I really have to implement some of that stuff into my gameplay. I am also thinking of cheap, intelligent decoys. Man, so many possibilities...
     
  15. Spets

    Spets Master Engineer

    Messages:
    3,214
    what if we can use this to aim to the center of a planet and make an orbiting satellite?

    EDIT: maybe also to autodock without using waypoints? and also with ships in movement?
     
    Last edited: Oct 15, 2015
  16. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    GetFreeDestination() takes following input vars: Vector to check (it points from your remote control to direction, you want to check), Distance (it's how long your path is checked for any intersections with physical objects), Ship radius (it's "thickness" of checked vector).
    It returns Free vector (it's eaqual to checked vector if no intersections found or it points to closest free direction).

    So, i take a target in a cross of 4 vectors and check them continuosly. I'll make detailed explanation with some pictures soon and post it here. Then i'll ask moderator to transfer this thread to ingame programming.
     
  17. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    It's not neccessary for orbiting in gravity range. Orbital mechanics works perfect in 1.094, it just requires more speed limit or more gravity range to orbit 50km planet.
    But i'm going to make a nasty tackler drone next, which is supposed to go on low orbit of enemy ship and cause troubles. This func is needed for that.
     
  18. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    How it works:
    Missile RemoteControl continuosly checks 5 vectors:

    1. FORWARD. It is 1m wide.
    This vector is pointed direct to target, if missile haven't lost its lock.
    It is used to check, target is still there and to measure distance. For distance measurement i check this vector from 10 to 3 times in a cycle to get distance.
    2. 4 "locking vectors". These vectors are 50 m wide, They are directed to points 50 m UP, DOWN, LEFT and RIGHT from FORWARD vector pointing.
    [​IMG]

    Let's look at LEFT and RIGHT pair of vectors.
    [​IMG]

    When they are checked with GetFreeDestination(), function returns free vectors for each one of them (original vectors are red, free vectors are green).
    And we can measure angle between original and free vectors for each side of target (A and B).
    If FORWARD points in geometrical center of target projection, angles A and B should be equal.
    If A > B, then FORWARD is pointing closer to right edge of target.
    We can use difference between A and B as an input signal for missile gyroscope Yaw axis.
    I take this value: (B-A)(A+B) / distance to trarget. You can add some multipliers to make missile more or less responsive.
    The same we do with UP and DOWN vectors. And use difference btw them as an input signal for gyroscope Pitch.
    Roll can be st to 0, or some value if you want missile to roll around it's Z while upproaching to target.
    My missile has all lateral thrusters pointing to one side, so i'm using roll for velocity dampening.
     
    • Like Like x 1
  19. Sinbad

    Sinbad Senior Engineer

    Messages:
    2,788
    ho-crap! this is a phased array tracking radar. thanks for the explanation on how the function works :D I'm off to go figure out how to scan a cone 25° around ships head out to 2km. awesome! :D
     
    • Like Like x 1
  20. Wellstat

    Wellstat Apprentice Engineer

    Messages:
    212
    This stuff is genius and needs more views. I'm currently testing a missile cruiser concept but uses drones to send sensors to fleet of large ships for detection, then launches all torpedos equally to targets based on the largest 10 sensor locked ships. Missile is spot on BUT the initial stage to get the drones to the fleet for sensor placement is next to impossible (by human hand) for moving fleets. This concept will be a perfect addition for the initial drone swarm. Thanks!

     
    • Like Like x 1
  21. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    Wow! Now i've gone to read about phased radars. Maybe there are many existing things, we can use in Space Engineers.
     
  22. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    Ok, will watch how you attach this thing to your ship.
    Script is not optimized yet, so it's too cpu-consuming. I will upgrade it.
     
  23. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    This is the script itself. It's far not perfect, there are much unneccessary normalizings, and i guess i can initialize less vectors.
    It only shows idea:

    Code:
    void    LockOn()  
       {  
         var pivotBlock = GridTerminalSystem.GetBlockWithName(ShipName+"RemCon") as IMyTerminalBlock;  
         Vector3D V3Dcenter = pivotBlock.GetPosition();
         Vector3D V3Dfow = pivotBlock.WorldMatrix.Forward;
      Vector3D V3Dup = pivotBlock.WorldMatrix.Up;
      Vector3D V3Dleft = pivotBlock.WorldMatrix.Left;
      Vector3D V3Ddown;
      Vector3D V3Dright;
         Vector3D V3DMyVelocity=V3Dcenter-V3DPrevCenter;
          Vector3D V3Dfree = (pivotBlock as IMyRemoteControl).GetFreeDestination(V3Dfow + V3Dcenter,Z1,20); 
          if ((V3Dfree!=V3Dfow+ V3Dcenter)&&(Z1>1000)) 
          {
            for (int x=0;x<Accuracy;x++) 
            { 
              Z=Z0+((Z1-Z0)/2); 
              V3Dfree = (pivotBlock as IMyRemoteControl).GetFreeDestination(V3Dfow + V3Dcenter,Z,20); 
              if (V3Dfree!=V3Dfow+ V3Dcenter) 
                Z1=Z; 
              else 
                Z0=Z; 
            } 
           Z1=Z+50;
           Z0=Z-50;
           Accuracy=3;
         }    
          else
          {
            Z=0;
            Z1=MaxDist;
            Z0=0;    
           Accuracy=10;        
        }    
         double AlphaUp;
         double AlphaDown;
         double AlphaLeft;
         double AlphaRight;
         V3Dup=Vector3D.Transform(Vector3D.Normalize(new Vector3D(0,Base,-Z1)),pivotBlock.WorldMatrix);
         V3Ddown=Vector3D.Transform(Vector3D.Normalize(new Vector3D(0,-Base,-Z1)),pivotBlock.WorldMatrix);
         V3Dleft=Vector3D.Transform(Vector3D.Normalize(new Vector3D(Base,0,-Z1)),pivotBlock.WorldMatrix);
         V3Dright=Vector3D.Transform(Vector3D.Normalize(new Vector3D(-Base,0,-Z1)),pivotBlock.WorldMatrix);
        
         Vector3D V3DfreeUp = Vector3D.Normalize((pivotBlock as IMyRemoteControl).GetFreeDestination(V3Dup,Z1,Base)-V3Dcenter);
         Vector3D V3DfreeDown = Vector3D.Normalize((pivotBlock as IMyRemoteControl).GetFreeDestination(V3Ddown,Z1,Base)-V3Dcenter);
         Vector3D V3DfreeLeft = Vector3D.Normalize((pivotBlock as IMyRemoteControl).GetFreeDestination(V3Dleft,Z1,Base)-V3Dcenter);
         Vector3D V3DfreeRight = Vector3D.Normalize((pivotBlock as IMyRemoteControl).GetFreeDestination(V3Dright,Z1,Base)-V3Dcenter);    
        
        
         AlphaUp=Math.Acos(Vector3D.Dot(V3Dup-V3Dcenter, V3DfreeUp));
         AlphaDown=Math.Acos(Vector3D.Dot(V3Ddown-V3Dcenter, V3DfreeDown));
         AlphaLeft=Math.Acos(Vector3D.Dot(V3Dleft-V3Dcenter, V3DfreeLeft));
         AlphaRight=Math.Acos(Vector3D.Dot(V3Dright-V3Dcenter, V3DfreeRight));
        
         double BetaUp=(AlphaUp-AlphaDown)/(AlphaUp+AlphaDown)/Z1;
         double BetaRight=(AlphaLeft-AlphaRight)/(AlphaLeft+AlphaRight)/Z1;  
         if (double.IsNaN(BetaUp)) 
         BetaUp=0;
         if (double.IsNaN(BetaRight)) 
         BetaRight=0;    
         if ((Z>500) && (FireMode!="Stop"))
         {
           TurnGroup(ShipName+"SpotLight","On");
           TurnGroup(ShipName+"Sound","On");
         }
         else
         {
           TurnGroup(ShipName+"SpotLight","Off");
           TurnGroup(ShipName+"Sound","Off");    
         }
         if (FireMode=="Launch") 
         {
           TurnGroup(ShipName+"Thr","On");     
           TurnGroup(ShipName+"Merge", "Off");     
           setThrustGroupLevel(ShipName+"ThrF",2304000);
           if(TickCount > 130)
             setGyroOverride(ShipName+"Gyroscope",true);
         }
         double AlphaVel=Vector3D.Dot(Vector3D.Normalize(pivotBlock.WorldMatrix.Forward),Vector3D.Normalize(V3DMyVelocity));
         Vector3D V3DampNorm=Vector3D.Normalize(Vector3D.Normalize(V3DMyVelocity)/AlphaVel-Vector3D.Normalize(pivotBlock.WorldMatrix.Forward));
         double Roll=Math.Acos(Vector3D.Dot(Vector3D.Normalize(pivotBlock.WorldMatrix.Up),V3DampNorm));
         if ((Vector3D.Normalize(pivotBlock.WorldMatrix.Left)-V3DampNorm).Length()>2/(Math.Sqrt(2)))
           Roll=-Roll;
      
         if (FireMode=="Launch") 
         {     
           int Koeff=10000;
          
         setGyroGroupLevel(ShipName+"Gyroscope", "Pitch", BetaUp*Koeff,1f);
         setGyroGroupLevel(ShipName+"Gyroscope", "Yaw", BetaRight*Koeff,1f);
         if(TickCount > 300)
           setGyroGroupLevel(ShipName+"Gyroscope", "Roll", -Roll*3,1f);    
         }
        
         Echo("FireMode: "+FireMode+"\nDistance: "+ Z.ToString()+"\n UP: "+BetaUp.ToString()+"\n RT: "+BetaRight.ToString());  
         //StoreValue("Distance: ", V3DMyVelocity.Length().ToString()+"\n AlphaVel: "+AlphaVel.ToString()+"\n Roll: "+Roll.ToString());  
         V3DPrevCenter=V3Dcenter;
         if (TickCount>20000)
           FireMode="Stop";
         if (FireMode!="Stop")
           Timer.GetActionWithName("TriggerNow").Apply(Timer);    
         else
           Timer.GetActionWithName("Stop").Apply(Timer);
         }
        
    And guys, how can i transfer this thread to In-game programming? Should i ask moderator or can do it myself?
     
    Last edited: Oct 19, 2015
  24. Sinbad

    Sinbad Senior Engineer

    Messages:
    2,788
    phased array is basicaly an antena that doesnt move. instead the beam is steered electronically by phase shifting the transmition elements. the long thin bar of a maritime navigation radar uses a similar idea (excaept its a fixed phase shift, so the antenna has to move) there are slots cut in the front of the bar at different distances from the RF source, the phase difference when the RF leaves the slots produced a waveform summing effect forming a beam. large focusing dishes are so WW2.
    i liken your script to a phased array in the fact that you can project a 'beam' of desired width and scan across an arc. (spiral scan i think for forward collision detection would be great)
     
  25. Klaern

    Klaern Apprentice Engineer

    Messages:
    296
    I'm pretty sure you have to ask a moderator
     
  26. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    it seems, GetFreeDestination() checks intersection not with the real shape of an object, but with its bounding sphere.
    So, if you attach a long strut of iron blocks to your ship, it will spoil it's signature protect it from this kind of torpedoes.
     
    Last edited: Oct 17, 2015
  27. Sinbad

    Sinbad Senior Engineer

    Messages:
    2,788
    this only has to work outside of 800m for a torpedo. after that turret homing can take over. as a 'nav radar' though, its a bit disappointing that it doesn't detect the acttual surface. I was planning on using plane detection to determine 'best path to avoid'
     
  28. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    A little experiment with GetFreeDestination():
     
    • Informative Informative x 1
  29. Sinbad

    Sinbad Senior Engineer

    Messages:
    2,788
    hmm. so it is detecting the bounding box. thats a little disapointing.
    how does it do with asteroids?
    also, have you considered a raster scan with one beam? steer the beam rather than steer the array, smaller, but the larger view angle you scan, the longer it takes.
     
  30. Pennywise

    Pennywise Apprentice Engineer

    Messages:
    338
    It deals the same way with asteroids. Yes, disappointing, and which is even more disappointing, it doesn't scan anything outside draw distance. This should be expected tho.
    For my torpedo it's not so bad, in the opposite, it makes things much more easy: every ship is a ball, whatever its real form is, so it doesnt matter from what side i look at it.

    I've made this frame only for experiment with blocks, for real scan you can use only one remote control and rotate scanning vector each time a bit.
    The problem is, this func is cpu-consuming as hell, so any scanning operations should be made with a decent delay.
     
    • Like Like x 1
    • Informative Informative x 1
Thread Status:
This last post in this thread was made more than 31 days old.