FreeSpace Releases > Scripting Releases

yup, guided missiles

(1/2) > >>

Nuke:

--- Code: ---#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

--- End code ---

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

Wanderer:
Cool.

Though the correct term is 'command guided'...

Nuke:
i only called em what they were called in descent :D

Wanderer:
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)

Nuke:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version