Simple remote control - Remote control mini car
Alistar Snook
Touch the physic object (car) to take the control and move it around your place.
It may be improved for more functions and options.
active = false
linearSpeed = 0.0
angularSpeed = 0.0
function state_entry()
ll.SetStatus(STATUS_PHYSICS, 1)
ll.InstantMessage(ll.GetOwner(),"Touch me to activate remote control")
end
function touch_start(toucher)
ll.RequestPermissions(ll.GetOwner(), PERMISSION_TAKE_CONTROLS)
end
function run_time_permissions(perm)
if bit32.band(perm, PERMISSION_TAKE_CONTROLS) then
ll.OwnerSay("Permissions granted.")
local controlMask = bit32.bor(CONTROL_FWD, CONTROL_BACK, CONTROL_ROT_LEFT, CONTROL_ROT_RIGHT)
ll.TakeControls(controlMask, 1, 0)
active = true
ll.SetTimerEvent(0.1)
end
end
function control(avatar_id, level, edge)
local start = bit32.band(level, edge)
local finish = bit32.band(bit32.bnot(level), edge)
local held = bit32.band(level, bit32.bnot(edge))
local untouched = bit32.bnot(bit32.bor(level, edge))
if (true) then
if bit32.band(held, CONTROL_FWD) ~= 0 then
linearSpeed = 12.0
elseif bit32.band(held, CONTROL_BACK) ~= 0 then
linearSpeed = -12.0
elseif (bit32.band(held, CONTROL_FWD) == 0 or bit32.band(held, CONTROL_BACK) == 0) then
linearSpeed = 0.0
end
if bit32.band(held, CONTROL_ROT_LEFT) ~= 0 and linearSpeed >= 0.0 then
angularSpeed = 2.5
end
if bit32.band(held, CONTROL_ROT_LEFT) ~= 0 and linearSpeed <= 0.0 then
angularSpeed = -2.5
end
if bit32.band(held, CONTROL_ROT_RIGHT) ~= 0 and linearSpeed >= 0.0 then
angularSpeed = -2.5
end
if bit32.band(held, CONTROL_ROT_RIGHT) ~= 0 and linearSpeed >= 0.0 then
angularSpeed = 2.5
end
if (bit32.band(held, CONTROL_ROT_LEFT) == 0 or bit32.band(held, CONTROL_ROT_RIGHT) == 0) then
angularSpeed = 0.0
end
end
end
function timer()
ll.SetVelocity(vector(linearSpeed, 0, 0), 1)
ll.SetAngularVelocity(vector(0, 0, angularSpeed), 1)
end
state_entry()
Log In