private void HandlePlayerShooting()
        {
            //if (!_command.AttackPressed) return;

            var ents = playerShipMatcher.GetMatches();

            foreach (var ent in ents)
            {
                if (playerCommand.AttackPressed)
                {
                    ZenLogger.LogGame("Attack triggered");
                    ExecuteAttack(ent);
                }
            }
        }
Exemple #2
0
        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}");
            }
        }