public void AIUpdate() { //update the time elapsed //keep a record of its old position so we can update its cell later //in this method Vector3 OldVelocity = aiAgent.Velocity(); Vector3 SteeringForce = Vector3.zero; //calculate the combined force from each steering behavior in the //vehicle's list SteeringForce = steeringBehaviour.Calculate(); //Acceleration = Force/Mass Vector3 acceleration = SteeringForce / aiAgent.Mass(); Vector3 gravityaccel = steeringBehaviour.GravityAccel(); grounded = (gravityaccel.magnitude > 0) ? true : false; aiAgent.Update(acceleration, gravityaccel, useWrapAround, Time.deltaTime); Vector3 vPos = aiAgent.VPos(); vPos.y = steeringBehaviour.GravityTruncate(vPos.y); aiAgent.SetVPos(vPos); //EnforceNonPenetrationConstraint(this, World()->Agents()); //update the vehicle's current cell if space partitioning is turned on if (isSmoothingOn()) { m_vSmoothedHeading = m_pHeadingSmoother.Update(aiAgent.Heading()); } //moveState if (steeringBehaviour.IsSteering()) { float epsillon = 0.01f; if (MathUtil.Equal(aiAgent.Velocity(), Vector3.zero, epsillon) && OldVelocity.magnitude >= epsillon) { if (onMoveComplete != null) { onMoveComplete(aiAgent, steeringBehaviour, MoveCompleteState.Reached); } } else if (gravityaccel.magnitude <= 0 && gravityaccel_old.magnitude > 0) { if (onMoveComplete != null) { onMoveComplete(aiAgent, steeringBehaviour, MoveCompleteState.Landed); } } } gameObject.transform.position = aiAgent.VPos(); if (useRotation) { Vector3 vDir = aiAgent.Heading(); if (vDir.magnitude > 0) { gameObject.transform.rotation = Quaternion.LookRotation(vDir); } } Vector3 target = gameObject.transform.position + gameObject.transform.rotation * Vector3.forward * aiAgent.BRadius(); gravityaccel_old = gravityaccel; DebugExtension.DebugCircle(target, 0.5f); }