private void MoveTowardPosition(AIShipComp nc, Vector3 moveToPosition) { //ZenGizmosDebug.Instance.targetPosition = moveToPosition; var pc = nc.GetComponent <PositionComp>().transform; var sc = nc.GetComponent <ShipComp>(); pc.rotation = //ZenMath.QuaternionUtil.SlerpLookAtTarget(pc, moveVector, 5f /*Rotation speed*/* Time.deltaTime); ZenMath.QuaternionUtil.SlerpLookAtTarget(pc, moveToPosition, 0.5f /*Rotation speed*/ * Time.deltaTime); //float faceAngle = Vector3.Dot(pc.forward, moveVector.normalized); Debug.DrawLine(pc.position, moveToPosition, Color.yellow); //if (faceAngle > 0.75) // only accelerate if pointing in the right general direction //{ // nc.GetComponent<RigidbodyComp>().rigidbody.AddForce( // pc.forward * // nc.GetComponent<ShipComp>().CurrentAcceleration * 60f * // Time.deltaTime); //} var rb = nc.GetComponent <RigidbodyComp>().rigidbody; //calc force Vector3 force = CalculateForce( pc.position, rb.velocity, moveToPosition, Vector3.zero); // #TODO: Change this zero to a next waypoint direction velocity //rb.AddForce(force, ForceMode.VelocityChange); Vector3 v = (force / rb.mass) * Time.deltaTime * sc.CurrentAcceleration / 60f; Vector3 totalVelocity = rb.velocity + v; Vector3 limitedV = Vector3.ClampMagnitude(totalVelocity, sc.CurrentMaxSpeed); rb.velocity = limitedV; //float maxspeed = nc.GetComponent<ShipComp>().CurrentMaxSpeed; //getting close to target if ((pc.position - moveToPosition).sqrMagnitude < 50.1f) { //Debug.Log("Close to target"); nc.Navigation.HasReachedTarget = true; } else { ZenLogger.LogGame($"Travel distance: {(pc.position - moveToPosition).sqrMagnitude}"); } }
private void RotateTowardPosition(AIShipComp nc, Vector3 targetPosition) { var pc = nc.GetComponent <PositionComp>().transform; var moveVector = targetPosition - pc.position; pc.rotation = ZenMath.QuaternionUtil.SlerpLookAtTarget(pc, moveVector, pc.GetComponent <ShipComp>().CurrentRotationSpeed * Time.deltaTime); }
private void UpdateOrbit(AIShipComp nc) { Vector3 moveto = nc.GetComponent <TargetComp>().target.position + nc.Navigation.TargetPositionOffset; MoveTowardPosition(nc, moveto); }
private void UpdateApproach(AIShipComp nc) { MoveTowardPosition(nc, nc.GetComponent <TargetComp>().target.position); }
private void UpdateAttacking(AIShipComp nc) { RotateTowardPosition(nc, nc.GetComponent <TargetComp>().target.position); }