CharacterBody3D stuck on Trimesh Static Bodies.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Vespiria

This is on Godot 4.0.2 latest, and this is a fairly small prototype I made just for testing multiplayer using steam matchmaking + enet.
To start, here is my script for movement :

func _physics_process(delta):
if not is_multiplayer_authority(): return

# Add the gravity.
if not is_on_floor():
	velocity.y -= gravity * delta

# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("left", "right", "forward", "back")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
_speed = SPEED
direction = direction.rotated(Vector3.UP, spring_arm_pivot.rotation.y)
if direction:
	if Input.is_action_pressed("run"):
		_speed = RUNSPEED
	velocity.x = lerp(velocity.x, direction.x * _speed, LERP_VAL)
	velocity.z = lerp(velocity.z, direction.z * _speed, LERP_VAL)
	armature.rotation.y = lerp_angle(armature.rotation.y, atan2(-velocity.x, -velocity.z), LERP_VAL)
	_movement.rpc(true)
else:
	velocity.x = lerp(velocity.x, 0.0, LERP_VAL)
	velocity.z = lerp(velocity.z, 0.0, LERP_VAL)
	_movement.rpc(false)

move_and_slide()

_movement() is just setting the animation tree to idle/walk/run values based on the currently velocity.length() / _speed for interpolating movement animations.

I’m not sure if the problem is my code or the created Trimesh Static Body that was generated by certain mesh’s. The mesh’s are parts of a decent sized map which is meant to be the prototype for testing. It is only made up of planes (maybe that’s an issue?) and I used careful precise measuring in blender to make sure everything lines up exactly.

Here is the main area I’ve found I’m getting stuck :

The red circles are all areas where the character seems to just fall right through and become unable to move/unable to stop the walking animation. Looking at the static body that was generated, it seems fine, I’ve even tried putting collision boxes in those spots to see if it helps but it does nothing, which makes me think it’s the code.

Here’s what it looks like when I get stuck :
https://streamable.com/frqs8z

Also my characterbody3d settings I have tried quite a few different settings and they haven’t really changed much besides make things worst.

Edit: Temporarily seemed to fix it by completely taking the generated trimesh out and just manually putting together my own with boxes. I really want to know what happened though so I can avoid this happening in the future.
Edit2: I went back into blender and added a solidify modifier to all of the floors/walls by just 0.1 and it seems to have fixed the issues I was having. It kind of sucks because it means I’m adding a bit more load but at least it works.

Having the same issue. My meshes are used as cells in a GridMap and often when going from a flat surface to a slope (or vice versa) my character gets stuck and I need to jump.

https://i.imgur.com/9BIgAq5.mp4

jer | 2023-06-27 17:07

:bust_in_silhouette: Reply From: jer

Not sure if this works for you but I did some tweaking on my character movement and zeroed out my Velocity.Y while on the floor. I did some debugging and found that I was setting my Velocity.Y to something like -20 by the time the player finished jumping and this value was simply left to persist while walking on the floor. I think when the player was moving from collision to collision this velocity caused the player to sink into the next mesh as they transitioned. As soon as I set it to 0 my player can walk smoothly across meshes - feels so good after having these issues.