Author Topic: yup, guided missiles  (Read 3975 times)

0 Members and 1 Guest are viewing this topic.

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
yup, guided missiles
Code: [Select]
#Global Hooks ;;guided missiles, proof of concept version
$GameInit:
[
-------------------------------
----------screen vars----------
-------------------------------

setscreenvars = function() --scalers and constants for multi res support
local w = gr.getScreenWidth()
local h = gr.getScreenHeight()
local cx = w/2
local cy = h/2
local wf = 0
local hf = 0
local awh = 0
local hires = false

if w >= 1024 then
wf = w / 1024
hf = h / 768
awh = (wf + hf) / 2
hires = true
else
wf = w / 640
hf = h / 480
awh = ((wf + hf) / 2) * 0.625
hires = false
end

return w,h,cx,cy,wf,hf,awh,hires
end

----------------------------
----------controls----------
----------------------------

mousejoy = function() --mousejoy function, short version
local X = io.getMouseX()
local Y = io.getMouseY()

if hires then
X = (X / 511.5) - 1
Y = (Y / 383.5) - 1
else
X = (X / 319.5) - 1
Y = (Y / 239.5) - 1
end

return X, Y
end

-------------------------
----------Maths----------
-------------------------

matx = function(ma, mb) --matrix multiply
local m = ba.createVector(0,0,0):getOrientation()
m[1] = ma[1] * mb[1] + ma[2] * mb[4] + ma[3] * mb[7]
m[2] = ma[1] * mb[2] + ma[2] * mb[5] + ma[3] * mb[8]
m[3] = ma[1] * mb[3] + ma[2] * mb[6] + ma[3] * mb[9]
m[4] = ma[4] * mb[1] + ma[5] * mb[4] + ma[6] * mb[7]
m[5] = ma[4] * mb[2] + ma[5] * mb[5] + ma[6] * mb[8]
m[6] = ma[4] * mb[3] + ma[5] * mb[6] + ma[6] * mb[9]
m[7] = ma[7] * mb[1] + ma[8] * mb[4] + ma[9] * mb[7]
m[8] = ma[7] * mb[2] + ma[8] * mb[5] + ma[9] * mb[8]
m[9] = ma[7] * mb[3] + ma[8] * mb[6] + ma[9] * mb[9]
return m
end

arbrot = function(a, r)
local s = math.sin(r)
local c = math.cos(r)
local t = 1 - c
local m = ba.createVector(0,0,0):getOrientation()

m[1] = t * a.x^2 + c
m[2] = t * a.x * a.y + s * a.z
m[3] = t * a.x * a.z - s * a.y

m[4] = t * a.x * a.y - s * a.z
m[5] = t * a.y^2 + c
m[6] = t * a.y * a.z + s * a.x

m[7] = t * a.x * a.z + s * a.y
m[8] = t * a.y * a.z - s * a.x
m[9] = t * a.z^2 + c

return m
end

w,h,cx,cy,wf,hf,awh,hires = setscreenvars()

]
$Simulation:
[

player = mn.Ships['Alpha 1']

x,y = mousejoy()
x = x * ba.getFrametime()
y = y * ba.getFrametime()

for i=1, #mn.Weapons do
local wep = mn.Weapons[i]
if wep.Class.Name == "Infyrno" then
local axis = wep.Orientation:unrotateVector(ba.createVector(1,0,0))
local mat = arbrot(axis,y)
wep.Orientation = matx(wep.Orientation,mat)

axis = wep.Orientation:unrotateVector(ba.createVector(0,1,0))
mat = arbrot(axis,x)
wep.Orientation = matx(wep.Orientation,mat)

wep.Physics.Velocity = wep.Orientation:unrotateVector(ba.createVector(0,0,wep.Class.Speed))
tracking = true
end
end

]
$HUD:
[
if tracking then gr.setColor(255,0,0,128) else gr.setColor(0,0,255,128) end
tracking = nil
gr.drawCircle(3,io.getMouseX()*wf,io.getMouseY()*hf)

]
#End

load up some infyrnos. use the mouse to steer them. :D
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

  

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Cool.

Though the correct term is 'command guided'...
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
i only called em what they were called in descent :D
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Well non-guided missile would be like a rocket or an arrow.. Guided missiles are all which have any homing and/or guidance build into them..

Coming to think about it.. semi-active radar homing missiles might be quite fun to try in freespace (missiles that require you to keep target 'painted' with radar ie. in center reticle)
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
thats doable. do some math to find out if the ship is in your cone. your weapon would be a smart heatseeker (theres a table flag to give heatseekers more brains iirc) or aspect. all youd really need to change the missile target to its velocity vector when the targets not in cone.

laser guided would be cool as well, simply set the missiles homing location to the point in space where your laser vector intersects hull. sorta like ssm but where your missile is being launched from your own ship and will chase anything the laser reflects off of. determining that would be difficult, as youd need some collision detection (quakec had traceline, give it a vector and it would follow it till something was hit, and return the distance). i know theres hooks for weapon colisions, but do they have access to the colision location vector and do they work on beams? im really only familiar with 3 hooks at the moment so i probibly could only make this work in a hackish fashon, such as using the players velocity vector times the target distance or more accurately a player unrotated  (0,0,target distance). of course with large targets this would work poorly at best.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
i know theres hooks for weapon colisions, but do they have access to the colision location vector and do they work on beams?

No and probably not. I don't remember testing beams. I believe the collision location is already calculated in the code itself, but there's no scripting access to the variable.

Check your PMs. :D
« Last Edit: August 31, 2007, 02:59:43 am by WMCoolmon »
-C

 

Offline jr2

  • The Mail Man
  • 212
  • It's prounounced jayartoo 0x6A7232
    • Steam
Code: [Select]
#Global Hooks ;;guided missiles, proof of concept version
$GameInit:
[
-------------------------------
----------screen vars----------
-------------------------------

setscreenvars = function() --scalers and constants for multi res support
local w = gr.getScreenWidth()
local h = gr.getScreenHeight()
local cx = w/2
local cy = h/2
local wf = 0
local hf = 0
local awh = 0
local hires = false

if w >= 1024 then
wf = w / 1024
hf = h / 768
awh = (wf + hf) / 2
hires = true
else
wf = w / 640
hf = h / 480
awh = ((wf + hf) / 2) * 0.625
hires = false
end

return w,h,cx,cy,wf,hf,awh,hires
end

----------------------------
----------controls----------
----------------------------

mousejoy = function() --mousejoy function, short version
local X = io.getMouseX()
local Y = io.getMouseY()

if hires then
X = (X / 511.5) - 1
Y = (Y / 383.5) - 1
else
X = (X / 319.5) - 1
Y = (Y / 239.5) - 1
end

return X, Y
end

-------------------------
----------Maths----------
-------------------------

matx = function(ma, mb) --matrix multiply
local m = ba.createVector(0,0,0):getOrientation()
m[1] = ma[1] * mb[1] + ma[2] * mb[4] + ma[3] * mb[7]
m[2] = ma[1] * mb[2] + ma[2] * mb[5] + ma[3] * mb[8]
m[3] = ma[1] * mb[3] + ma[2] * mb[6] + ma[3] * mb[9]
m[4] = ma[4] * mb[1] + ma[5] * mb[4] + ma[6] * mb[7]
m[5] = ma[4] * mb[2] + ma[5] * mb[5] + ma[6] * mb[8]
m[6] = ma[4] * mb[3] + ma[5] * mb[6] + ma[6] * mb[9]
m[7] = ma[7] * mb[1] + ma[8] * mb[4] + ma[9] * mb[7]
m[8] = ma[7] * mb[2] + ma[8] * mb[5] + ma[9] * mb[8]
m[9] = ma[7] * mb[3] + ma[8] * mb[6] + ma[9] * mb[9]
return m
end

arbrot = function(a, r)
local s = math.sin(r)
local c = math.cos(r)
local t = 1 - c
local m = ba.createVector(0,0,0):getOrientation()

m[1] = t * a.x^2 + c
m[2] = t * a.x * a.y + s * a.z
m[3] = t * a.x * a.z - s * a.y

m[4] = t * a.x * a.y - s * a.z
m[5] = t * a.y^2 + c
m[6] = t * a.y * a.z + s * a.x

m[7] = t * a.x * a.z + s * a.y
m[8] = t * a.y * a.z - s * a.x
m[9] = t * a.z^2 + c

return m
end

w,h,cx,cy,wf,hf,awh,hires = setscreenvars()

]
$Simulation:
[

player = mn.Ships['Alpha 1']

x,y = mousejoy()
x = x * ba.getFrametime()
y = y * ba.getFrametime()

for i=1, #mn.Weapons do
local wep = mn.Weapons[i]
if wep.Class.Name == "Infyrno" then
local axis = wep.Orientation:unrotateVector(ba.createVector(1,0,0))
local mat = arbrot(axis,y)
wep.Orientation = matx(wep.Orientation,mat)

axis = wep.Orientation:unrotateVector(ba.createVector(0,1,0))
mat = arbrot(axis,x)
wep.Orientation = matx(wep.Orientation,mat)

wep.Physics.Velocity = wep.Orientation:unrotateVector(ba.createVector(0,0,wep.Class.Speed))
tracking = true
end
end

]
$HUD:
[
if tracking then gr.setColor(255,0,0,128) else gr.setColor(0,0,255,128) end
tracking = nil
gr.drawCircle(3,io.getMouseX()*wf,io.getMouseY()*hf)

]
#End

load up some infyrnos. use the mouse to steer them. :D

Can you release them when they are locked on, like in descent (press fire button again, and they home like normal).

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
you could do that with weapon children and remote-detonate. you can pretty much use this on any non-homing missile, homing ones work but are abit jumpy. you can even use primaries but it tends to screw up their collosions.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Cobra

  • 212
  • Snake on a Cain
    • Minecraft
    • Skype
    • Steam
    • Twitter
Ooh! OOH! Do the Helios! :D
To consider the Earth as the only populated world in infinite space is as absurd as to assert that in an entire field of millet, only one grain will grow. - Metrodorus of Chios
I wept. Mysterious forces beyond my ken had reached into my beautiful mission and energized its pilots with inhuman bomb-firing abilities. I could only imagine the GTVA warriors giving a mighty KIAAIIIIIII shout as they worked their triggers, their biceps bulging with sinew after years of Ivan Drago-esque steroid therapy and weight training. - General Battuta