Character Goes through floor when approching player.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By vonflyhighace2
:warning: Old Version Published before Godot 3 was released.

I have a 3D enemy that moves towards the player when they are in range. The enemy for some reason moves down into the floor the closer it gets to the player. is this a bug? any ideas how to fix.

You have to show us the code that you are using for your enemy’s movement.

timoschwarzer | 2016-12-22 21:41

I’m using the distance between characters form my movement method. I should also mention that I’m using rigid body and not kinematic body.

var colliderBounds = get_shape(0).get_extents();
		var posOffset =  Vector3(self.get_translation().x + colliderBounds.x, self.get_translation().y , self.get_translation().z + colliderBounds.z);
		var moveTo = (target.get_translation() - posOffset);
		self.global_translate(Vector3().linear_interpolate(moveTo, moveSpeed * delta));

vonflyhighace2 | 2016-12-23 00:24

The problem could be that you are moving a rigid body with set pos, rigid bodies are meant to be moved with forces and managed by the physics engine.

Not sure what happens here exactly but the engine may be trying to work over the bodies and get bad collision data.

So, if not using physics, don’t use bodies (at least, not rigid bodies)

eons | 2016-12-23 14:13

As far as I’ve seen and tested using translate to move a rigid body does still allow it to be controlled by the physics engine. My problem that I just realized was that the physics engine was also controlling rotation for my character which is something that you do not want to happen when using rigid body for character motion. setting the rigid body to character which disabled rotation by the physics engine solved my problem.

vonflyhighace2 | 2016-12-23 21:32