Hard Light Productions Forums

FreeSpace Releases => Scripting Releases => Topic started by: Nuke on August 27, 2007, 02:53:52 pm

Title: yup, guided missiles
Post by: Nuke on August 27, 2007, 02:53:52 pm
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
Title: Re: yup, guided missiles
Post by: Wanderer on August 27, 2007, 03:02:17 pm
Cool.

Though the correct term is 'command guided'...
Title: Re: yup, guided missiles
Post by: Nuke on August 27, 2007, 03:04:35 pm
i only called em what they were called in descent :D
Title: Re: yup, guided missiles
Post by: Wanderer on August 30, 2007, 04:20:28 am
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)
Title: Re: yup, guided missiles
Post by: Nuke on August 30, 2007, 07:01:33 pm
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.
Title: Re: yup, guided missiles
Post by: WMCoolmon on August 31, 2007, 02:50:06 am
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
Title: Re: yup, guided missiles
Post by: jr2 on August 31, 2007, 04:25:29 pm
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).
Title: Re: yup, guided missiles
Post by: Nuke on August 31, 2007, 08:40:11 pm
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.
Title: Re: yup, guided missiles
Post by: Cobra on October 22, 2007, 01:16:44 pm
Ooh! OOH! Do the Helios! :D