# My character is randomly wiggling when moved

#1

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``````
0 Likes

#2

At what x,y positions does your character begin to “wiggle” or is it always?

Using builtin material?

It always helps to make a small minimal reproduction you can upload.

1 Like

#3

I think the problem lies in this line:

Due to this line sign of pos.x is never changed.

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.

2 Likes

#4

@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).

TrueTileCollision - Copy.zip (43.3 KB)

0 Likes

#5

I’m not seeing “wiggle” can you record what you see?

https://www.screentogif.com/

1 Like

#6

@Pkeod, screentogif seemed too unstable for capturing it. I used OBS.

0 Likes

#7

``````	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)
``````

Do you see any huge spikes in ms?

2 Likes

#8

Compilation failed. Closing ‘)’ missing but:

``````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``````
0 Likes

#9

You’re missing the last bit of the code snippet I posted. `end)`

1 Like

#10

Silly me.
I don’t know what to really look, but it seemed OK and for my surprise it didn’t have random wiggle.

0 Likes

#11

Something weird is happening, maybe someone else has an idea.

1 Like

#12

I have NO IDEA what’s happening. I went bit further on my physics and there’s not wiggle anymore… And code has nothing to do with it.

0 Likes

#13

Maybe related to my issue.

0 Likes

#14

If you can, maybe try my uploaded project few replays back.
My character DID that when it moved on static camera.

1 Like

#15

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.

1 Like

#16

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).

1 Like

#17

I have added basic controls to get it working on mobile, but I don’t notice any wiggle even on my phone, so this is a different issue than mine.

1 Like

#18

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.

0 Likes

#19

Can someone explain what’s happening? It started again out of blue. Here I captured that stutter stops when I turn on debugging.

Here’s the project (debug run in player script). TileCollisionPlatformer.zip (62.4 KB)

Happened before last update and stayed after update. Got to say really killing the vibe for working on project.
EDIT: F2 is peak record debugger

0 Likes

#20

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.

0 Likes