Hey i have been trying to figure out why my code isn’t working… its very simple but the object doesn’t move, I looked around for some sample code and found the exact same code that seemed to be working. Which makes me think maybe I tweaked a project setting. Anyways all i am trying to do is move the object by 100 on the x-axis every second.
It seems that the new position is correct but that the next frame when it does go.get_position() its still using the previous frames position, as if the set_position() didn’t do anything.
Any ideas?
function init(self)
-- msg.post(".", "acquire_input_focus")
self.velocity = vmath.vector3(100, 0, 0);
end
function final(self)
-- Return input focus when the object is deleted
-- msg.post(".", "release_input_focus")
end
function update(self, dt)
-- Just want to move on the x axis by 100..
local pos = go.get_position()
local delta_pos = self.velocity * dt
print("CURRENT POSITION: " .. pos)
print("DELTA POSITION " .. delta_pos)
print("NEW POSITION " .. (pos + delta_pos))
print(dt)
go.set_position(pos + delta_pos)
end
Console Output
DEBUG:SCRIPT: CURRENT POSITION: [280.255066, 146.436356, 0.000000]
DEBUG:SCRIPT: DELTA POSITION [1.666667, 0.000000, 0.000000]
DEBUG:SCRIPT: NEW POSITION [281.921722, 146.436356, 0.000000]
DEBUG:SCRIPT: 0.016666667535901
DEBUG:SCRIPT: CURRENT POSITION: [280.255066, 146.436356, 0.000000]
DEBUG:SCRIPT: DELTA POSITION [1.666667, 0.000000, 0.000000]
DEBUG:SCRIPT: NEW POSITION [281.921722, 146.436356, 0.000000]
DEBUG:SCRIPT: 0.016666667535901
INFO:DLIB: SSDP: Done on address 192.168.2.20