# Sprites tied to physics lag one frame behind (Issue-4152)

**URL:** <https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859>\
**Category:** Bugs\
**Created:** [January 8, 2019, 1:01pm UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859 "2019-01-08T13:01:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [January 8, 2019, 1:01pm UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/1 "2019-01-08T13:01:52Z")

</div>

I have a dynamic ball bouncing on a static surface. The ball overlaps the surface for one frame, before bouncing up. How can this be avoided? I use the Orthographic camera.

Edit: This only seems to happen when the surface is using a built in Box Shape. When a Collision Shape is used I haven’t been able to replicate it.

---

<div class="post-metadata">

**Author:** ![Johan\_Beck-Noren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/johan_beck-noren/32/2622_2.png) [@Johan\_Beck-Noren](https://forum.defold.com/u/Johan_Beck-Noren)\
**Post date:** [January 8, 2019, 1:31pm UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/2 "2019-01-08T13:31:54Z")

</div>

> [@totebo](#):
>
> Edit: This only seems to happen when the surface is using a built in Box Shape. When a Collision Shape is used I haven’t been able to replicate it.

Are you using 2D or 3D physics? What do you mean collision shape? A collision object can have _shapes_ box/capsule/sphere.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [January 8, 2019, 1:49pm UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/3 "2019-01-08T13:49:05Z")

</div>

2D physics. I mean a custom collision shape, as defined here:

 ![49](https://forum-defold.b-cdn.net/uploads/default/original/2X/2/2109807948c4b01477b38155a906b8a4b3305f8a.png)

For some reason I only seem to get this issue with a “built in” box shape.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [January 15, 2019, 3:20pm UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/4 "2019-01-15T15:20:04Z")

</div>

Having continued my game I get this behaviour on all shapes most of the time. Is there a way to avoid this one frame “tunneling” of dynamic objects?

It’s not a game breaker, but it’s noticeable when the camera follows an object that burrows into solid objects for one frame. Can I force a graphic update at the same time as the physics is updated somehow?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 15, 2019, 11:19pm UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/5 "2019-01-15T23:19:23Z")

</div>

Can you please share a minimal example of this behaviour?

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [January 16, 2019, 11:35am UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/6 "2019-01-16T11:35:28Z")

</div>

> [@britzl](#):
>
> Can you please share a minimal example of this behaviour?

I was just about to! A minimal project (no code!) is attached, showing the issue clearly:

With debug:

 ![45](https://forum-defold.b-cdn.net/uploads/default/original/2X/1/1c342dea0c0260e3c0a67a00d189c1761072b463.png)

Without debug:

 ![54](https://forum-defold.b-cdn.net/uploads/default/original/2X/f/f537b8819286d3b7d40ed391d8465e806772097d.png)

[PhysicsTunneling.zip](https://forum.defold.com/uploads/default/original/2X/0/04a0e171d703dda4d516809a7a35722480038dc5.zip) (34.6 KB)

---

<div class="post-metadata">

**Author:** ![dmitriy](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dmitriy/32/18452_2.png) [@dmitriy](https://forum.defold.com/u/dmitriy)\
**Post date:** [January 16, 2019, 12:53pm UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/7 "2019-01-16T12:53:02Z")

</div>

I believe, this is how physics works with a such high gravity. Continuous Collision Detection (making ball a bullet) may fix this, but this is not accessible in Defold.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [January 16, 2019, 1:15pm UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/8 "2019-01-16T13:15:48Z")

</div>

> [@dmitriy](#):
>
> I believe, this is how physics works with a such high gravity

That might be true, although I’ve never seen this before as I’ve never had gravity set to so high. Is there an alternative way to make things move naturally? With the default settings all objects added appear planet sized and move very slowly.

---

<div class="post-metadata">

**Author:** ![Johan\_Beck-Noren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/johan_beck-noren/32/2622_2.png) [@Johan\_Beck-Noren](https://forum.defold.com/u/Johan_Beck-Noren)\
**Post date:** [January 16, 2019, 1:43pm UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/9 "2019-01-16T13:43:57Z")

</div>

> [@totebo](#):
>
> That might be true, although I’ve never seen this before I’ve neve had gravity set to so high. Is there an alternative way to make things move naturally? With the default settings all objects added appear planet sized and move very slowly.

In game.project under Physics you can set the scale of the physics simulation. I think Box2D maps 1 pixel to 1 meter in its simulation, so setting the scale to e.g. 0.02 would map 50 pixels to 1 meter instead.

Regarding the overlap issue, after some googling it seems like a quirk in Box2D unfortunately. Described in better detail in this thread; [http://www.box2d.org/forum/viewtopic.php?t=6438#p29192](http://www.box2d.org/forum/viewtopic.php?t=6438#p29192)

There is an ongoing feature we are developing to decouple the physics simulation from the game loop, allowing you to run the physics at a higher (or lower) rate. It’s not prioritised in our backlog yet and still early in development: [Teaser Fridays and Roadmap talks - #89 by Johan\_Beck-Noren](https://forum.defold.com/t/teaser-fridays-and-roadmap-talks/2803/89)

Being able to run physics at a higher rate should make the overlap smaller and not as noticeable.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [January 16, 2019, 2:22pm UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/10 "2019-01-16T14:22:11Z")

</div>

> [@Johan\_Beck-Noren](#):
>
> There is an ongoing feature we are developing to decouple the physics simulation from the game loop, allowing you to run the physics at a higher (or lower) rate.

That would be amazing. Thanks for the reply!

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [January 18, 2019, 12:40pm UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/11 "2019-01-18T12:40:52Z")

</div>

> [@dmitriy](#):
>
> Continuous Collision Detection (making ball a bullet) may fix this, but this is not accessible in Defold.

This has turned into a bit of a problem now, as the ball in my game actually gets stuck within the terrain. I’ve spent all morning trying to solve it, without success. Here’s what I’ve tried so far:

- Adjust gravity and scale
- Limit the velocity by adding linear damping
- Cap the velocity programmatically, by reading linear velocity and send a counter impulse to stop the ball going too fast
- Add a trigger to detect a collision and slam on the brakes with impulses
- Add other shapes inside the ball

Any other ideas?!

---

<div class="post-metadata">

**Author:** ![Johan\_Beck-Noren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/johan_beck-noren/32/2622_2.png) [@Johan\_Beck-Noren](https://forum.defold.com/u/Johan_Beck-Noren)\
**Post date:** [January 18, 2019, 1:47pm UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/12 "2019-01-18T13:47:41Z")

</div>

If you are trying to “fix” the dynamic physics simulation by modifying linear velocity etc. you might be better off using a kinematic collision object and handle the simulation and collisions yourself instead. That way you get more explicit control of how the collision objects behave.

The manuals on resolving kinematic collisions should be helpful; [Physics in Defold](https://www.defold.com/manuals/physics/#_resolving_kinematic_collisions)

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [January 18, 2019, 1:52pm UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/13 "2019-01-18T13:52:08Z")

</div>

> [@Johan\_Beck-Noren](#):
>
> If you are trying to “fix” the dynamic physics simulation by modifying linear velocity etc. you might be better off using a kinematic collision object and handle the simulation and collisions yourself instead.

That may be what I’ll end up doing actually, I’m banging this ball against a brick wall. 🙂

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [June 4, 2019, 10:34am UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/14 "2019-06-04T10:34:55Z")

</div>

![38](https://forum-defold.b-cdn.net/uploads/default/original/3X/c/5/c55967921441a1323333f6b9876996c9f6dec569.png)

I’m at this again!

If -10 is “natural gravity”, how do I create a dynamic body football bouncing naturally? No matter what settings I use, I seem to end up with a football that moves much, much too slowly for it to feel “natural”.

Has someone done this and can point me in the right direction?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 4, 2019, 10:56am UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/15 "2019-06-04T10:56:29Z")

</div>

More reasonable values would be gravity -1000 and physics scale 0.01. Our template projects have been updated with these values btw.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [June 4, 2019, 10:59am UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/16 "2019-06-04T10:59:46Z")

</div>

> [@britzl](#):
>
> More reasonable values would be gravity -1000 and physics scale 0.01.

Yes, those values appear more natural. BUT they have the issue of tunneling, which I’m trying to avoid by being a good boy and following all the rules. 🙂

> [@britzl](#):
>
> Our template projects have been updated with these values btw.

I noticed that! But it still says -10 is “natural”, but I think that may be natural only on a small comet.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [June 4, 2019, 11:01am UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/17 "2019-06-04T11:01:08Z")

</div>

> [@totebo](#):
>
> But it still says -10 is “natural”,

Where does it say this?

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [June 4, 2019, 11:03am UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/18 "2019-06-04T11:03:06Z")

</div>

> [@britzl](#):
>
> Where does it say this?

See screenshot above. It’s in the tooltip when you hover over the textbox.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [June 4, 2019, 11:23am UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/19 "2019-06-04T11:23:43Z")

</div>

> [@totebo](#):
>
> -10 is “natural”

I guess the comment refers to our common constant of gravity (~9.82) here on earth.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [June 4, 2019, 11:38am UTC](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859/20 "2019-06-04T11:38:11Z")

</div>

So, to recap:

- Gravity appears earth-like at -1000 and physics scale 0.01.
- With this level of gravity dynamic objects burrow into each other for one frame on collision.
- There is no solution, aside from manually dealing with physics using kinematic objects.

😭

[Next page](https://forum.defold.com/t/sprites-tied-to-physics-lag-one-frame-behind-issue-4152/39859.md?page=2)
