Example #1
0
    void LateUpdate()
    {
        if (!uLink.Network.isAuthoritativeServer || networkView.owner == uLink.NetworkPlayer.server || uLink.Network.isClient)
        {
            return;
        }

        if (wasGrounded)
        {
            lastVelY = 0;
        }
        lastVelY -= gravityAcceleration * Time.deltaTime;

        CollisionFlags flags = character.Move(new Vector3(0, lastVelY * Time.deltaTime, 0));

        wasGrounded = ((flags & CollisionFlags.CollidedBelow) != 0);

        if (serverHasLastOwnerPos && (uLink.Network.isCellServer || networkView.owner.isConnected))
        {
            serverHasLastOwnerPos = false;
            Vector3 serverPos = transform.position;
            Vector3 diff      = serverPos - serverLastOwnerPos;

            if (Vector3.SqrMagnitude(diff) > sqrMaxServerError)
            {
                networkView.UnreliableRPC("AdjustOwnerPos", uLink.RPCMode.Owner, serverPos);
            }
            else
            {
                networkView.UnreliableRPC("GoodOwnerPos", uLink.RPCMode.Owner);
            }
        }
    }
    void FindClosestTarget()
    {
        for (byte i = 0; i < otherPlayers.Length; i++)
        {
            if (otherPlayers[i])
            {
                if (closestTarget == null)
                {
                    closestTarget   = otherPlayers[i];
                    closestTargetCC = otherPlayers[i].GetComponent <CharacterController>();
                    continue;
                }

                if (Vector3.SqrMagnitude(transform.position - closestTarget.position) >
                    Vector3.SqrMagnitude(transform.position - otherPlayers[i].position))
                {
                    if (ak47Picked || rocketPicked)
                    {
                        closestTargetCC.CharacterUI.OpenCloseCrosshair(false);
                        otherPlayers[i].GetComponent <CharacterController>().CharacterUI.OpenCloseCrosshair(true);
                        otherPlayers[i].GetComponent <CharacterController>().CharacterUI.CrosshairImage.color =
                            closestTargetCC.CharacterUI.CrosshairImage.color;
                    }
                    closestTarget   = otherPlayers[i];
                    closestTargetCC = otherPlayers[i].GetComponent <CharacterController>();
                }
            }
        }
    }
Example #3
0
        public bool CanHit(CharacterData attacker, CharacterData target)
        {
            if (Vector3.SqrMagnitude(attacker.transform.position - target.transform.position) < Stats.MaxRange * Stats.MaxRange)
            {
                return(true);
            }

            return(false);
        }
Example #4
0
        public ValueTuple <Cell, Vector3> Raycast(Ray ray)
        {
            foreach (var cell in Cells.OrderBy(c => Vector3.SqrMagnitude(c.CenterPoint - ray.origin)))
            {
                var intersection = cell.Raycast(ray);
                if (intersection.HasValue)
                {
                    return(new ValueTuple <Cell, Vector3>(cell, intersection.Value));
                }
            }

            return(new ValueTuple <Cell, Vector3>(null, Vector3.zero));
        }
Example #5
0
        private void CheckPassingThroughRings()
        {
            var toRemove = new List <ClosestRing>();

            SetClosestRings();
            foreach (var ring in closestRings)
            {
                if (!ring.PassedThroughCenter && ring.Checker.CheckCollecting(transform.position))
                {
                    ring.PassedThroughCenter = true;
                }
                else
                {
                    var distanceVector      = ring.Collider.gameObject.transform.position - transform.position;
                    var sqrDistanceToCenter = Vector3.SqrMagnitude(distanceVector);
                    if (sqrDistanceToCenter < leavingSqrDistance)
                    {
                        continue;
                    }

                    if (ring.PassedThroughCenter)
                    {
                        CollectRing(ring.Collider.gameObject);
                        toRemove.Add(ring);
                    }
                    else
                    {
                        ring.Collider.enabled = true;
                        toRemove.Add(ring);
                    }
                }
            }
            foreach (var ring in toRemove)
            {
                closestRings.Remove(ring);
            }
        }
    private void SetupScene()
    {
        Random.InitState(Seed);

        List <Sphere> spheres = new List <Sphere>();

        for (int i = 0; i < SpheresMax; i++)
        {
            Sphere sphere = new Sphere();

            bool intersectionWithOthers = false;

            do
            {
                sphere.radius = SphereRadius.x + Random.value * (SphereRadius.y - SphereRadius.x);
                Vector2 randomPos = Random.insideUnitCircle * SpherePlacementRadius;
                sphere.position = new Vector3(randomPos.x, sphere.radius, randomPos.y);

                // check intersection
                intersectionWithOthers = false;
                foreach (var other in spheres)
                {
                    float minDist = sphere.radius + other.radius;

                    if (Vector3.SqrMagnitude(sphere.position - other.position) < minDist * minDist)
                    {
                        intersectionWithOthers = true;
                        break;
                    }
                }
            } while (intersectionWithOthers);

            //-- material parameters
            Color color = Random.ColorHSV();

            if (Random.value < 0.1) // emissive material
            {
                sphere.specular   = Vector3.zero;
                sphere.smoothness = 0.0f;

                var emission = Random.ColorHSV(0, 1, 0, 1, 1.0f, 2.0f);
                sphere.emission = new Vector3(emission.r, emission.g, emission.b);
                sphere.albedo   = sphere.emission; // both albedo and specular cannot be zero, because of artifacts /0
            }
            else
            {
                bool metal = Random.value < 0.5f;

                sphere.albedo     = metal ? Vector3.zero : new Vector3(color.r, color.g, color.b);
                sphere.specular   = metal ? new Vector3(color.r, color.g, color.b) : Vector3.one * 0.04f;
                sphere.smoothness = Random.value > 0.75 ? 1.0f : Random.value;
                sphere.emission   = Vector3.zero;
            }

            spheres.Add(sphere);
        }

        //-- fill computeBuffer
        if (_bufferSpheres == null)
        {
            int stride = UnsafeUtility.SizeOf <Sphere>();
            _bufferSpheres = new ComputeBuffer(spheres.Count, stride);
        }

        _bufferSpheres.SetData(spheres);
    }