I'm developping a zombie game with networks. I was just killing zombies in the game, but suddenly zombies and the player start falling down through the terrain.
And when I was standing on a box, it happens again~ suddenly my character was falling down. It seems like physics does not work anymore.
I'm using unity steer, and angry behave for AI. Give me a hands plz~
ps: Thank you for your replying Bunny83
- It is a 'normal' network game~
- And I was just playing my self(just me), I saw that happening in my PC.
- And Yes, when I was standing on a box suddenly falling down.
- And the zombie and the player does not has a rigidbody.
- And unity steer use a CharacterController.
Here is my zombie's source.
And the player's source is, I use BootCamp's soldier's script.
void Update()
{
if (!networkView.isMine)
return;
if (energy < 0)
return;
if (behaviorTree != null &&
behaviorTree.Tick(this, null) != BehaveResult.Running)
behaviorTree.Reset(this, null);
Vector3 dir;
if (zombiAni.IsFiring)
{
dir = new Vector3(finder.TargetDirection.x, 0, finder.TargetDirection.z);
if (dir != Vector3.zero)
transform.rotation = Quaternion.LookRotation(-dir);
}
else
{
dir = new Vector3(moveDirection.x, 0, moveDirection.z);
if (Speed <= 0.1f)
dir = new Vector3(finder.TargetDirection.x, 0, finder.TargetDirection.z);
if (dir != Vector3.zero)
transform.rotation = Quaternion.LookRotation(dir);
if (zombiAni.IsWalking ||
zombiAni.IsRunning)
{
UpdateDirection();
UpdateMovement(false);
RegenerateLocalSpace(moveDirection);
}
else
UpdateMovement(true);
if (dir != Vector3.zero)
transform.rotation = Quaternion.LookRotation(-dir);
}
}
private void UpdateDirection()
{
if (!finder.IsTargetFounded)
return;
if (MaxForce == 0 || MaxSpeed == 0 || Time.deltaTime == 0)
return;
Profiler.BeginSample("Calculating forces");
Vector3 force = Vector3.zero;
foreach (Steering steering in Steerings)
{
if (steering.enabled)
force += steering.WeighedForce;
}
Profiler.EndSample();
Vector3 clippedForce = Vector3.ClampMagnitude(force, MaxForce);
Vector3 newAcceleration = (clippedForce / Mass);
if (newAcceleration.sqrMagnitude == 0 && !HasInertia)
{
Speed = 0;
}
Vector3 newVelocity = Velocity;
smoothedAcceleration = OpenSteerUtility.blendIntoAccumulator(0.4f,
newAcceleration,
smoothedAcceleration);
newVelocity += smoothedAcceleration * Time.deltaTime;
newVelocity = Vector3.ClampMagnitude(newVelocity, MaxSpeed);
Speed = newVelocity.magnitude;
moveDirection = newVelocity;
}
private void UpdateMovement(bool isUpdateGravityOnly)
{
//Apply gravity
if (isGrounded)
upSpeed = 0;
else
upSpeed -= gravity * Time.deltaTime;
Vector3 movement = new Vector3(0, upSpeed, 0);
if (!isUpdateGravityOnly)
movement += (moveDirection * Time.deltaTime);
//Move controller
CharacterController controller = GetComponent<CharacterController>();
CollisionFlags flags = controller.Move(movement);
isGrounded = (flags & CollisionFlags.CollidedBelow) != 0;
}