Strange behaviour of setDirection
thisnickwasfree opened this issue · 8 comments
Looks like setDirection somehow ignores mesh:reset (): an object gets right (well, looks like) direction in the beginning, but then continue to rotate, if I use setDirection and reset mesh in a cycle to the same vector.
Used once setDirection works fine.
I can not reconstruct the problem. Both reset and setDirection overwrites the current transform, setDirection uses the position extracted from the previous transform. But the rotation should never be affected. Can you send me the few lines where you use setDirection please?
Well, something like this… Old code, now I moved direction from the cycle. I'll check everything again carefully.
function Missle:Update(dt)
self.progress = self.progress + 25 * dt;
self.coordinates = self.vec * self.progress + self.initial;
if (self.targetcoordinates - self.coordinates):length () <= 1 then
self.Shooter:MissleImpact (self.Target);
self:Remove ();
end;
end;
function Missle:Draw()
local _floatdirection = self.Shooter:GetFloatDirection ();
local _vec = vec3(_floatdirection.x, _floatdirection.z, -1 * _floatdirection.y);
local _up = vec3 (0, 1, 0);
self.mesh:setDirection (_vec, _up);
dream:draw (self.mesh, self.coordinates.x, self.coordinates.z, -1 * self.coordinates.y);
self.mesh:reset ();
end;
hmm, on the first glance it looks fine. I would place the reset before the setDirection but it should work.
I'll check. Looks like an objects rotates around vertical axis even without cycle, but it not so notisable at short distances. Do not know if the problem in 3dreamengine's functions or in my code, so continuing searchng.
https://github.com/thisnickwasfree/3dreamengine_tests
The object fly from vec3 (10, 0, -1) to vec3 (-20, 0, -100) and it's rotating.
Flying from vec3 (10, 0, -1) to vec3 (20, 0, -100) works fine.
I've placed only one object at scene, but you can change coordinates in Scene.lua (str. 9) if you need.
One more thing. I count the direction like -1 * (destination - initial). Without -1 the object fly in tail-forward mode (wide part is a head).
Thanks, I messed up the math and fixed it. Tell me if its still not working as expected.
Hm, I've placed new version of 3dreamengine to demo and see no differ.
Vector with negative x still gives additional rotation.
Hm, I've placed new version of 3dreamengine to demo and see no differ.
Vector with negative x still gives additional rotation.
Whoops, wrong order of multiplications. Fixed now.
Note that it is dream:draw(x, y, z, sx, sy, sz): in your demo you have an additional nil value, which applies a vec(1, 10, 10) scale. (The last 10 goes into void)