i wrote it just now, i tried the rotateY first but i found it was too unreliable (as expected)
to adjust the speed i've commented the line (also fixed the ability to open/close the door while it's opening/closing)
p.s. i expect it only goes too fast because your frame rate is high, for me (at 60fps which IMO is already higher than id expect a full game to run at) it's fine.
pressed = 0
local angle = {}
local new_angle = {}
local startx = {}
local starty = {}
local startz = {}
local temp = {}
local delay = {}
function door_manual_init(e)
angle[e] = nil
temp[e] = -1
end
function door_manual_main(e)
if angle[e] == nil then
delay[e] = GetTimer(e) + 1100
startx[e] = g_Entity[e]['x']
starty[e] = g_Entity[e]['y']
startz[e] = g_Entity[e]['z']
angle[e] = -1
elseif angle[e] == -1 then
if GetTimer(e) < delay[e] then
CollisionOff(e)
MoveForward(e,50)
else
angle[e] = RotateToPoint(e,startx[e],startz[e])
angle[e] = angle[e] + 180
SetRotation(e,0,angle[e],0)
SetPosition(e,startx[e],starty[e],startz[e])
CollisionOn(e)
end
else
if GetPlayerDistance(e) < 120 then
if g_Entity[e]['activated'] == 0 then
Prompt("Open door?")
if GetScancode() == 18 and pressed == 0 then
pressed = 1
SetActivated(e,1)
temp[e] = 0
end
elseif g_Entity[e]['activated'] == 2 then
Prompt("Close door?")
if GetScancode() == 18 and pressed == 0 then
pressed = 1
SetActivated(e,3)
temp[e] = 0
end
end
end
if temp[e] >= 0 then
if g_Entity[e]['activated'] == 1 then
if temp[e] < 90 then
temp[e] = temp[e] + 0.5 --adjusts speed of rotation (remember to change the 2nd below)
new_angle[e] = angle[e] + temp[e] --change to - (minus) if you want it to rotate the other way & change the other to + (plus)
SetRotation(e,0,new_angle[e],0)
else
angle[e] = new_angle[e]
temp[e] = -1
SetActivated(e,2)
CollisionOff(e)
end
elseif g_Entity[e]['activated'] == 3 then
if temp[e] < 90 then
temp[e] = temp[e] + 0.5 --match the previous temp[e] modifier above
new_angle[e] = angle[e] - temp[e] --change this if you change the other 1
SetRotation(e,0,new_angle[e],0)
else
angle[e] = new_angle[e]
temp[e] = -1
SetActivated(e,0)
CollisionOn(e)
end
end
end
end
if GetScancode() == 0 then
pressed = 0
end
end
-------
function RotateToPoint(e,x,z)
if g_Entity[e] ~= nil and x > 0 and z > 0 then
local destx = x - g_Entity[e]['x']
local destz = z - g_Entity[e]['z']
local angle = math.atan2(destx,destz)
angle = angle * (180.0 / math.pi)
if angle < 0 then
angle = 360 + angle
elseif angle > 360 then
angle = angle - 360
end
SetRotation(e,0,angle,0)
return angle
end
end
life\'s one big game
windows vista ultimate
i5 @3.3ghz, 4gb ram, AMD R9 200 series , directx 11