Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Lua code and some learning
2017-03-21, 01:17 AM
Post: #1
Basic Lua code and some learning
Hoping someone can help here, currently messing about with submarines and looking to do something a bit more advanced with missiles while learning some Lua to take myself forward in the process.
Looking for something nice and simple I can learn from that to start with takes a vertically launched missile and does the following:

From a launch depth of -100 meters flies straight up until over +50 meters (weirdly this seems to be my big sticking point, do I use SetLuaControlledMissileAimPoint?)

Turns straight towards target - I believe I base this off targetInfo.AimPointPosition

Leads target based on speed - I believe from some reading I'm after proportional navigation (but feel free to correct me)

Also, is it possible to not light up the missile thruster until an arbitrary value (say -3m)?
Find all posts by this user
Quote this message in a reply
2017-03-21, 01:43 AM
Post: #2
RE: Basic Lua code and some learning
I believe it is now possible to control variable thrusters, but I do not know the interface. Otherwise--yes, SetLuaControlledMissileAimPoint is how you set guidance. For your purpose you probably want to just set it to the missile's present position plus an arbitrary Y amount.

Target leading has been the subject of considerable debate--I think target prediction is easier to implement than proportional navigation, but both have been done. My advice here is to look up missile scripts people have posted and read their algorithms--there are a range of approaches with differing degrees of speed/simplicity and sophistication.

Allr andask.
Find all posts by this user
Quote this message in a reply
2017-03-21, 11:13 AM (This post was last modified: 2017-03-21 11:17 AM by 6dwavenminer.)
Post: #3
RE: Basic Lua code and some learning
It's really suprising what you can do with just setting the aim pos of the missile:

Feel free to trawl through my missile code and ask any questions: http://www.fromthedepthsgame.com/forum/s...?tid=27116
(For target prediction that also accounts for acceleration, check out the "PredictInterceptPosition" function on line 258)

But if you want something alot more simple to start with, to get your missile to just head straight up to a certain altitude, then head towards your target in a javelin guidance style use something like:
(Note: coded in browser, not tested)

local DirectEngagementRange = 180;
local CruisingAltitude = 50;

for t=0, I:GetLuaTransceiverCount()-1 do
for m=0, I:GetLuaControlledMissileCount(t)-1 do

local Missile = I:GetLuaControlledMissileInfo(t,m);
local MissilePos = Missile.Position;
local Target = I:GetTargetInfo(MainFrameID,0);
local TargetPos = Target.AimPointPosition;
local RangeToTarget = Vector3.Distance(Target ,TargetPos );

if RangeToTarget > DirectEngagementRange then
if MissilePos.y < CruisingAltitude then
--Get to the correct height
I:SetLuaControlledMissileAimPoint(t,m,MissilePos.x,CruisingAltitude + 1,MissilePos.z);
else
--Now head to target
I:SetLuaControlledMissileAimPoint(t,m,Target.x,CruisingAltitude,Target.z);
end
else
--Now aim directly at target
I:SetLuaControlledMissileAimPoint(t,m,Target.x,Target.y,Target.z);
end
end
end

I consider my ambassadors to be the best in the world, they always seem to come to a successful resolution, I just wish they could learn to use a few less missiles on passing seagulls.
Find all posts by this user
Quote this message in a reply
2017-03-21, 11:41 AM
Post: #4
RE: Basic Lua code and some learning
Many thanks for the advice folks, considering from my readings it would appear the two of yourselves are somewhat of an authority on the subject.
I take it "Target.x" means it moves along the x axis in the targets direction?
Find all posts by this user
Quote this message in a reply
2017-03-21, 11:50 AM
Post: #5
RE: Basic Lua code and some learning
(2017-03-21 11:41 AM)Das_Sheep Wrote:  Many thanks for the advice folks, considering from my readings it would appear the two of yourselves are somewhat of an authority on the subject.
I take it "Target.x" means it moves along the x axis in the targets direction?

Exactly, although it should be noted that in this case it is using global coordinates.

I consider my ambassadors to be the best in the world, they always seem to come to a successful resolution, I just wish they could learn to use a few less missiles on passing seagulls.
Find all posts by this user
Quote this message in a reply
2017-03-21, 11:59 AM
Post: #6
RE: Basic Lua code and some learning
(2017-03-21 11:50 AM)6dwavenminer Wrote:  I take it "Target.x" means it moves along the x axis in the targets direction?

Exactly, although it should be noted that in this case it is using global coordinates.
[/quote]

Cool. Is there a particular issue with using global coordinates? (basically just because you said it "should be noted")
Find all posts by this user
Quote this message in a reply
2017-03-21, 12:25 PM
Post: #7
RE: Basic Lua code and some learning
(2017-03-21 11:59 AM)Das_Sheep Wrote:  
(2017-03-21 11:50 AM)6dwavenminer Wrote:  I take it "Target.x" means it moves along the x axis in the targets direction?

Exactly, although it should be noted that in this case it is using global coordinates.

Cool. Is there a particular issue with using global coordinates? (basically just because you said it "should be noted")
[/quote]

No, just making sure you know, when I first started playing around with missiles I thought it used local coordinates, as in the missile would always be (0,0,0).

I consider my ambassadors to be the best in the world, they always seem to come to a successful resolution, I just wish they could learn to use a few less missiles on passing seagulls.
Find all posts by this user
Quote this message in a reply
2017-03-21, 12:33 PM
Post: #8
RE: Basic Lua code and some learning
(2017-03-21 12:25 PM)6dwavenminer Wrote:  
(2017-03-21 11:59 AM)Das_Sheep Wrote:  
(2017-03-21 11:50 AM)6dwavenminer Wrote:  I take it "Target.x" means it moves along the x axis in the targets direction?

Exactly, although it should be noted that in this case it is using global coordinates.

Cool. Is there a particular issue with using global coordinates? (basically just because you said it "should be noted")

No, just making sure you know, when I first started playing around with missiles I thought it used local coordinates, as in the missile would always be (0,0,0).
[/quote]

Happy days then. Had it in my head that the launching vessel might end up being 0,0,0 from the missile's point of view but haven't gotten anywhere near that far yet
Find all posts by this user
Quote this message in a reply
2017-03-21, 12:40 PM (This post was last modified: 2017-03-21 12:52 PM by 6dwavenminer.)
Post: #9
RE: Basic Lua code and some learning
(2017-03-21 12:33 PM)Das_Sheep Wrote:  
(2017-03-21 12:25 PM)6dwavenminer Wrote:  
(2017-03-21 11:59 AM)Das_Sheep Wrote:  
(2017-03-21 11:50 AM)6dwavenminer Wrote:  I take it "Target.x" means it moves along the x axis in the targets direction?

Exactly, although it should be noted that in this case it is using global coordinates.

Cool. Is there a particular issue with using global coordinates? (basically just because you said it "should be noted")

No, just making sure you know, when I first started playing around with missiles I thought it used local coordinates, as in the missile would always be (0,0,0).

Happy days then. Had it in my head that the launching vessel might end up being 0,0,0 from the missile's point of view but haven't gotten anywhere near that far yet
[/quote]

I think I need to quickly clear something up,for global coordinates,(0,0,0) is actually an arbitary point in the world, y is up/down, x is either north/south or east/west, and z is the other one. Sorry if I caused any confusion.

I consider my ambassadors to be the best in the world, they always seem to come to a successful resolution, I just wish they could learn to use a few less missiles on passing seagulls.
Find all posts by this user
Quote this message in a reply
2017-03-21, 12:55 PM
Post: #10
RE: Basic Lua code and some learning
(2017-03-21 12:40 PM)6dwavenminer Wrote:  
(2017-03-21 12:33 PM)Das_Sheep Wrote:  
(2017-03-21 12:25 PM)6dwavenminer Wrote:  
(2017-03-21 11:59 AM)Das_Sheep Wrote:  
(2017-03-21 11:50 AM)6dwavenminer Wrote:  I take it "Target.x" means it moves along the x axis in the targets direction?

Exactly, although it should be noted that in this case it is using global coordinates.

Cool. Is there a particular issue with using global coordinates? (basically just because you said it "should be noted")

No, just making sure you know, when I first started playing around with missiles I thought it used local coordinates, as in the missile would always be (0,0,0).

Happy days then. Had it in my head that the launching vessel might end up being 0,0,0 from the missile's point of view but haven't gotten anywhere near that far yet

I think I need to quickly clear something up,for global coordinates,(0,0,0) is actually an arbitary point in the world, y is up/down, x is either north/south or east/west, and z is the other one. Sorry if I caused any confusion.
[/quote]

Not a worry, figured global referred to that, I just assumed missiles would use some form of relative or instance specific coordinate set as their parent is their origin point.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)