oh ok. it was just a thought anyway. my real goal was player operated turrets, which seems to be working. aiming is a different matter, i wanted to render a crosshair on the screen that indicates which way the turret was pointing. is there an easy way to convert an orientation matrix to a vector? if i could do that then i could just get the screen coords of that vector.
another problem. the turret apears to rotate right no matter which way the ship is oriented. however when you fire it, if you have any roll whatsoever, the turren fires at a funky angle. both of theese problems come from the fact that i suck at calculus or whatever. oh heres the code, its based off the example in this thread, which i dont fully understand. it works with any bomber with turrets and this build.
#Global Hooks
$GameInit:
[
--all this stuff is for multires support, for getting true width and height, and for generating factors to scale coords by
w = gr.getScreenWidth()
h = gr.getScreenHeight()
if w >= 1024 then
wf = w / 1024
else
wf = w / 640
end
if h >= 768 then
hf = h / 768
else
hf = h / 480
end
dead = 15
--mousejoy function, returns a value from -100 to 100 depending on the mouse's position
mousejoy = function(deadzone)
local X = ((ms.getX() * wf) - (w/2)) * (200/w)
local Y = ((ms.getY() * hf) - (h/2)) * (200/h)
if X < deadzone and X > -deadzone then X=0 end
if Y < deadzone and Y > -deadzone then Y=0 end
return X, Y
end
--generic crosshair function
crosshair = function(x,y)
gr.setColor(0,255,0,200)
gr.drawGradientLine(x+20,y+20,x+10,y+10)
gr.drawGradientLine(x-20,y+20,x-10,y+10)
gr.drawGradientLine(x+20,y-20,x+10,y-10)
gr.drawGradientLine(x-20,y-20,x-10,y-10)
end
]
$HUD:
[
player = mn.getShipByName("Alpha 1")
mX, mY = mousejoy(dead)
gr.setColor(0,255,0,255)
gr.drawCircle(5,mX+200,mY+200)
gr.setColor(100,100,255,100)
gr.drawRectangle(100,100,300,300)
gr.setColor(128,128,0,200)
gr.drawRectangle(200-dead,200-dead,200+dead,200+dead)
mX = mX * ba.getFrametime(false) / 25
mY = mY * ba.getFrametime(false) / 25
if player ~= nil then
for i=1, player:getNumSubsystems() do
ori = player[i].Orientation
ori.h = ori.h + mX
player[i].Orientation = ori
ori = player[i].GunOrientation
ori.p = ori.p + mY
if ori.p > 0 then
ori.p = 0
elseif ori.p < -math.pi/2 then
ori.p = -math.pi/2
end
player[i].GunOrientation = ori
if ms.isButtonDown(MOUSE_LEFT_BUTTON) then
player[i]:fireWeapon(1, 1000)
end
if ms.isButtonDown(MOUSE_RIGHT_BUTTON) then --hold down y + mouse up or down to change your deadzone
dead = dead + mY
if dead < 1 then dead = 1 end
if dead > 99 then dead = 99 end
end
--lof = player[i].GunOrientation
--if lof:getScreenCoords() ~= false then
-- chX, chY = lof:getScreenCoords()
-- crosshair(chX * wf,chY * hf)
--end
end
end
]
#End