So, I have scaled camera focused view (stationary while learning), in case that’s important.
I’m running this function from the LUA module without assigning it to a variable.
I put test positioning just like I’m planning to put further as I’m putting my physics together.
Does someone have any clue why it might wiggle?
function h_move(inst)
--Get direction
local hin = 0
if (bit.band(inst.buttons, right) > 0) then --bitmasking for right button
hin = hin + 1
end
if (bit.band(inst.buttons, left) > 0) then --bitmasking for left button
hin = hin - 1
end
local x = inst.spd.x
if hin ~= 0 then --move
x = x + hin * inst.ACC
x = clamp(x, -inst.MAX, inst.MAX)
else --deaccelerate
x = approach(x, 0, inst.DCC) --(value, goal, ammount)
end
--testing
inst.spd.x = x
local pos = go.get_position(inst.MY_URL)
pos.x = math.floor(math.abs(pos.x + x)) * sign(pos.x)
go.set_position(pos, inst.MY_URL)
print(pos.x)
end
I will try to explain with an example. Assume initially pos.x=1 and and x=-3, after first iteration pos.x will be 2: floor(abs(-2))*1.
After the second iteration pos.x will be 1: floor(abs(-1))*1. So it will wiggle between 1 and 2.
@Pkeod I’m just at the start of building my own physics and I got to horizontal speed calculations. Just for testing purposes, I put set_position. It wiggles randomly all the time (pixel forward or backward from supposed position). Numbers show that applied speed or position is all right but visually it is bugged.
@lutfi.altin No, I’m rounding to whole numbers there. Meaning it will be moved when rounding down returns an integer value (in my case either 1, -1, 2 or -2 since max speed is 2).
That calculation is a simplified version to get int values but still, it returns exactly needed values. You can see in the attached project (It is only the start of the physics system).
timer.delay(1, false, function()
profiler.enable_ui(true)
profiler.set_ui_mode(profiler.MODE_RECORD)
profiler.set_ui_mode(profiler.MODE_SHOW_PEAK_FRAME) -- comment this line to not show peak only
end)
function init(self)
msg.post(".", "acquire_input_focus")
local url = msg.url()
local id = go.get_id(".")
init_physics(self, id, url, "/level/background#tiles", "collision", 16, 2, 4.8, 0.23, 1, 4)
set_hitbox(self, -5, 4, 16, 0)
timer.delay(1, false, function() -- here ')' doesn't fix
profiler.enable_ui(true)
profiler.set_ui_mode(profiler.MODE_RECORD)
--profiler.set_ui_mode(profiler.MODE_SHOW_PEAK_FRAME) -- comment this line to not show peak only
end
I tried your project on my imac and I don’t notice wiggle at all. Unfortunately I cannot try on my iphone (where my issue happens) because there aren’t controls for mobile on your project.
I haven’t gone that far with Defold, but if you can add any controls to give input left or right it will move.
or call funtion button_left(self) or button_right(self).
Ok, so it started to do it again and this time it did it with debugger:
I don’t know what is Engine.Sim. Here’s the project file TrueTileCollision - Copy.zip (121.4 KB)
Could it be that having open other applications do this? Because I closed down some applications and didn’t notice that stutter.
For me, I don’t see the stuttering when I run your project as is, but I do see it when I uncheck vsync and set update rate to 60 in game.project. What this tells me is that your video card might not be allowing vsync to be on when it’s enabled in game (this is something the engine still struggles to get right) which then makes it stutter for whatever reason. Check your graphics card settings and see if you can make a profile for the game to always force vsync on, or set vsync on by default for all programs. Ideally solving this so it “just works” should be a huge priority for engine team and probably is.