Hi together,
I have a problem with the collision for my enemies. I already tried RigidBody and CharacterController, but nothing works.
With Rigidbody the enemies move correct but glitch into each (no collision) For rigidbody i set “Use gravity = true” and freeze postion + rotation complitely (but shouldn´t have anything todo with the collision), so gravity works, bot collision doesn´t:
No collision, so they glitch into each other
// If the target is in pull distance and the mob doesn´t walk back to the start point
if (distanceToPlayer <= PullDistance && !_turn && !_playerCharacter.IsDead)
{
_animation.Play(GlobalConstants.Walk);
_turn = false;
// Rotate/look to the target
Vector3 direction = _target.position - _mob.position;
direction.y = 0;
_rigidbody.MoveRotation(Quaternion.Slerp(_mob.rotation, Quaternion.LookRotation(direction), RotationSpeed * Time.deltaTime));
if (distanceToPlayer > MinDistanceToPlayer)
{
// Move to the target
_rigidbody.MovePosition(_mob.forward * MovementSpeed);
}
}
If i use a CharacterController, the collision works, but it looks like the gravity doesn´t work. As soon as they turn to the player, the their position moves on the y axe (so they “fly”) and if they collide with another enemy or the player, they “jump” over it (values of the character controller are all default):
(The left spider is 0.8f over the ground and the right spider “jumps” over the player cause of collision), so i guess, the gravity doesn´t work. I actually thought with SimpleMove cares on gravity ?!
// If the target is in pull distance and the mob doesn´t walk back to the start point
if (distanceToPlayer <= PullDistance && !_turn && !_playerCharacter.IsDead)
{
_animation.Play(GlobalConstants.Walk);
_turn = false;
// Rotate/look to the target
Vector3 direction = _target.position - _mob.position;
direction.y = 0;
_mob.rotation = Quaternion.Slerp(_mob.rotation, Quaternion.LookRotation(direction), RotationSpeed * Time.deltaTime);
if (distanceToPlayer > MinDistanceToPlayer)
{
// Move to the target
_cC.SimpleMove(_mob.forward * MovementSpeed);
}
}
Do i have to set anything else ? Does my terrain needs anything special or do i have something in the code ?
I know that´s actually very basic, but i really don´t get it. I already wasted a lot of hours for this with google and trying different things and coulnd´t get any result…
*To be clear, i just want that the enemies don´t glitch into each other, but don´t jump away or anything if they collide.
Kind regards,
Sphinks