Hi everyone,
I imported a simple low poly map and then turned it into a Trimesh, but when I create simple enemy characters, they seem to be inside the floor for some reason, even though the collisions look perfect in debug → collision shapes. You can see the enemies are sort of in the ground, not walking on it, even though it does move up/down correctly and collides with other objects in the scene fine.
Here is my physics function in case that could be causing any issue:
func _physics_process(delta):
if player:
var distance = global_transform.origin.distance_to(player.global_transform.origin)
if distance < attack_range and can_attack:
attack()
var direction = (player.global_transform.origin - global_transform.origin).normalized()
direction.y = 0
direction = direction.normalized()
var movement_velocity = Vector3(
direction.x * speed,
direction.y,
direction.z * speed
)
knockback = knockback.lerp(Vector3.ZERO, 5 * delta)
velocity.x = movement_velocity.x + knockback.x
velocity.z = movement_velocity.z + knockback.z
if not is_on_floor():
velocity.y -= 9.8 * delta
move_and_slide()
If your character is in it’s own scene, it may be located below the x/z surface.
1 Like
I moved the meshinstance up a little and it looks good now and doesn’t look like its stuck in the floor anymore, but why do I have to do that as now the collisionshape doesnt match with the meshinstance?
The capsule shape has a default height of 2. You have to set the position y of your collision shape and mesh to 1 to position them “on the floor” in your character scene.
Basically move capsule shapes by half of their height up to make them align horizontally on 0.
The red and blue axis lines in the editor tell you where position 0 is.
1 Like
For me, moving the meshinstance 1m above the collisionshape now made it hover over the ground by a lot, 0.6m above the collisionshape worked the best for me. I’m not sure why though, why 0.6m when my capsule height is 2m? Is this just for capsuleshapes?
I just figured out something, I replaced the trimesh static body child floor with a box and it worked perfectly fine, so it must be an issue with the trimesh?
Edit: Sorry for so many replies, I just started using godot forum and kept on messing up how to reply
This isn’t an issue with the character, but the trimesh static body floor because it works on primitives.
Here’s what fixed it: I needed to flip the normals in blender, then everything worked perfectly!