Esempio n. 1
0
        public unsafe void DroneMovement(FixedUpdateEvent e, DroneNode drone)
        {
            DroneOwnerComponent      droneOwner      = drone.droneOwner;
            Rigidbody                body            = drone.rigidbody.Rigidbody;
            DroneMoveConfigComponent droneMoveConfig = drone.droneMoveConfig;

            if (droneOwner.Incarnation.Alive && droneOwner.Rigidbody)
            {
                this.ApplyMovingForce(body, droneMoveConfig, droneOwner);
            }
            Rigidbody rigidbody = drone.rigidbody.Rigidbody;

            this.ApplyStabilization(rigidbody);
            Rigidbody rigidbody3 = null;

            if (drone.Entity.HasComponent <UnitTargetComponent>())
            {
                Entity target = drone.Entity.GetComponent <UnitTargetComponent>().Target;
                if (target.HasComponent <RigidbodyComponent>())
                {
                    rigidbody3 = target.GetComponent <RigidbodyComponent>().Rigidbody;
                }
            }
            if (rigidbody3 != null)
            {
                Vector3  position   = rigidbody3.position;
                Vector3 *vectorPtr1 = &position;
                vectorPtr1->y += 0.5f;
                this.ApplyTargetingForce(rigidbody, (position - rigidbody.position).normalized);
            }
            else if (droneOwner.Incarnation.Alive && droneOwner.Rigidbody)
            {
                this.ApplyTargetingForce(rigidbody, (droneOwner.Rigidbody.transform.forward - (Vector3.up * 0.5f)).normalized);
            }
        }
Esempio n. 2
0
        private void ApplyMovingForce(Rigidbody body, DroneMoveConfigComponent config, DroneOwnerComponent owner)
        {
            Vector3 vector3   = (owner.Rigidbody.transform.position + config.FlyPosition) - body.position;
            float   magnitude = vector3.magnitude;
            Vector3 vector4   = vector3 / magnitude;

            if (magnitude > 1f)
            {
                body.AddForceSafe(vector4 * Mathf.Clamp(magnitude * config.Acceleration, 0f, config.MoveSpeed));
            }
        }