1
嗨如何設置加速度計0指向用戶的位置/他持有的天使? 我使用:將加速度計設置爲用戶位置
delta = -40/180*math.pi --
cos_delta, sin_delta = math.cos(delta), math.sin(delta)
要偏移,但居屋我可以讓設備被拿下的天使是0
#額外的代碼:
-- Speed of Movement with tilt. You can change it ans see the effects.
tiltSpeed = 30;
motionx = 0;
motiony = 0;
rotation = 0;
--delta = -50/180*math.pi -- 30 degrees, maybe should have minus sign
--cos_delta, sin_delta = math.cos(delta), math.sin(delta)
-- Firstly, you need to get accelerometer's values in "zero position"
-- probably, inside onTilt event
local gy, gz = event.yGravity, event.zGravity
local len = math.sqrt(gy*gy+gz*gz) * (gz < 0 and -1 or 1)
cos_delta = gz/len
sin_delta = -gy/len
local function onTilt(event)
motionx = tiltSpeed * event.xGravity
motiony = tiltSpeed * (cos_delta*event.yGravity + sin_delta*event.zGravity)
end
是用來代替「delta = -40/180 * math.pi cos_delta,sin_delta = math.cos(delta),math.sin(delta)」? –
得到這個錯誤「game.lua線:319嘗試對本地'gy'執行算術(無值)」 –
顯示您的代碼。 –