Why the enemy model jumps at the beginning? (SOLVED)

Hello everyone. I have my 3D enemy character that follows player when he gets close. The problem is, when player gets close for the first time, enemy jumps and sometimes bounces of around before it is stabilized. After it calms down, it behaves as expected with no problem. Why this might be happening?

Note: At first, enemy feet is slightly clipping through ground but it is fixed once it starts moving. Is this a physics engine problem/behavior?

At the beginning (Clipped):

Later (Correct):

Collision Shape:

Maybe you could print the penetration distance and normal that you have on the skeleton? Perhaps you are getting a very large value for some reason?

When it jumps, 1.6 is impulse and normal is quite larger compared to when it is calm. Also, enemy has a dynamic capsule collision shape

Right when enemy jumps:

DEBUG:SCRIPT: hash: [contact_point_response] - { [“own_group”] = hash: [enemy]
,[“applied_impulse”] = 1.6667248010635
,[“mass”] = 10
,[“other_mass”] = inf
,[“other_id”] = hash: [/AmongUsLevel/go1]
,[“other_group”] = hash: [default]
,[“group”] = hash: [default]
,[“relative_velocity”] = vmath.vector3(-7.5541928268308e-10, 2.4139881134033e-05, -0.00030843005515635)
,[“distance”] = -1.9967551452282e-06
,[“position”] = vmath.vector3(46.864433288574, 0.078195929527283, -31.62193107605)
,[“life_time”] = 0
,[“normal”] = vmath.vector3(-3.1291656341637e-05, 0.99999982118607, 0.0006139125325717)
,[“other_position”] = vmath.vector3(46.045433044434, 0.056614000350237, -24.465505599976)
,}


After is is stabilized

DEBUG:SCRIPT: hash: [contact_point_response] - { [“applied_impulse”] = 0
,[“life_time”] = 0
,[“mass”] = 10
,[“relative_velocity”] = vmath.vector3(-0, -5.1440868377686, -0.00032592852949165)
,[“other_position”] = vmath.vector3(46.045433044434, 0.056614000350237, -24.465505599976)
,[“own_group”] = hash: [enemy]
,[“other_group”] = hash: [default]
,[“group”] = hash: [default]
,[“other_id”] = hash: [/AmongUsLevel/go1]
,[“position”] = vmath.vector3(46.757843017578, -0.067016780376434, -31.824153900146)
,[“other_mass”] = inf
,[“normal”] = vmath.vector3(-8.2101365705967e-07, 1, -1.6420273141193e-06)
,[“distance”] = 0.14519768953323
,}

Is your CO dynamic or kinematic? Did you scale the capsule? Can you spawn enemy above the ground with larger offset and check if its initial clipping that is pushed out?

Suggest to also turn on debug in physics, can shine some light on what’s happening

What happens in your code when the enemy is “activated”? You mentioned something about the player getting close to the enemy?

Initially, the update method includes a return statement that prevents movement until the player is nearby. After player gets close, the internal code makes the skeleton move. I assumed it was because its collision shape is not awake? so I tried calling physics.wakeup(“#collisionobject”) but it didn’t help.

These are good advice. @Asatte please check this.

I indeed have scaled the collection and it was the problem. Gave the model its own go parent and resized that instead and solved the issue. Thank you :slight_smile:

@britzl One thing I learned about Defold 3D is “do not resize collision objects or collections“. This was not a thing for other engines so I am curious why should we avoid it with Defold? A little insight on how Defold operates would be helpful :slight_smile:

This isn’t true. Scaling object/containers (especially non-uniformly) causes tons of problems in physics engines, even in modern ones like bullet, Box2D, or Unity’s PhysX backend. You can find plenty of related issues in both Godot and Unity as well. Always scale you assets in editor(Blender etc.) and import, never scale the colliders or containers :slight_smile:

What I mean is, I scaled 3d collision shapes/scenes on Godot on many projects but did not experience similar bugs. I am not well informed how they handle it on the background but it is not much problem on their side as far as I know/experienced

You were lucky then, but it’s not recommended. Also, scaling a model might impact performance too.

Warning: With a non-uniform scale, this node will likely not behave as expected. It is advised to keep its scale the same on all axes and adjust its collision shape(s) instead.

Godot does not currently support scaling of physics bodies or collision shapes.

If you search a bit more, you can find tons of complaints.

I use Godot for 3D a lot so I guess I am indeed very lucky. I will keep not scaling them in mind so it is not much of a problem.

Good to know it is a physics engine’s problem and not Defold’s. Thank you for the answer

@selimanac yes for non-uniform scaling, but for uniform it must work? At least I cannot think of a reason why it should not. I have only encountered this issue with capsule, everything else works like a charm. I tried to deal with it before, but it seems like its not only problem with collision penetration, but also with collision messages, as it seems collision messages obtained from scaled CO are totally wrong…

1 Like