Esempio n. 1
0
    private void Update()
    {
        SetBlom07Mov();

        _emitterDistance        = Vector3.Distance(blom_07.transform.position, Player.GetPlayerTransform().position);
        _currentEmitterPosition = new Vector3(blom_07.transform.position.x, blom_07.transform.position.y, blom_07.transform.position.z);

        switch (CharacterState.IsAbilityFlagActive(ABILITY_FLAG.SUPERHEARING))
        {
        case false:
            if (!isFollow)
            {
                if (_emitterDistance < blom_07._maxDistance && _emitterDistance != _lastEmitterDistance)
                {
                    _followValue         = Mathf.InverseLerp(blom_07._maxDistance, 0, _emitterDistance);
                    _d_followValue       = Math.Round(_followValue, 1);
                    _r_followValue       = Convert.ToSingle(_d_followValue);
                    _lastEmitterDistance = _emitterDistance;
                }
                _targetRotation            = listener.transform.rotation;
                _relativeRotation          = Quaternion.Lerp(blom_07.transform.rotation, _targetRotation, _r_followValue);
                blom_07.transform.rotation = _relativeRotation;

                blom_07.Set_Parameter(blom_07._blom07DistanceParameterId, 0);
            }

            if (isFollow)
            {
                blom_07.transform.rotation = listener.transform.rotation;
                blom_07.Set_Parameter(blom_07._blom07DistanceParameterId, 1);
            }

            blom_07.Set_Parameter(blom_07._isFollowParameterId, _r_followValue);
            blom_07.Set_Parameter(blom_07._blom07PotionParameterId, 0);

            blom_07.transform.position = _followCollider.ClosestPoint(Player.GetPlayerTransform().position);
            break;

        case true:
            blom_07.Override_Max_Distance(blom_07._maxDistance * 1.25f);
            if (!isFollow)
            {
                MoveEmitter(_currentEmitterPosition, _followCollider.ClosestPoint(Player.GetPlayerTransform().position));

                blom_07.Set_Parameter(blom_07._blom07DistanceParameterId, 0);
            }

            if (isFollow)
            {
                blom_07.Set_Parameter(blom_07._blom07DistanceParameterId, 1);

                MoveEmitter(_currentEmitterPosition, _originalEmitterPosition);
            }
            blom_07.Set_Parameter(blom_07._blom07PotionParameterId, 1);
            blom_07.Set_Parameter(blom_07._isFollowParameterId, 0.55f);
            break;
        }
    }
Esempio n. 2
0
    private void Update()
    {
        foreach (EventRef_Follow followEvent in eventRefs)
        {
            _distance = Vector3.Distance(followEvent.transform.position, listener.transform.position);

            if (!isFollow)
            {
                if (_distance < followEvent.maxDistance && _distance != _lastDistance)
                {
                    _followValue   = Mathf.InverseLerp(followEvent.maxDistance, 0, _distance);
                    _d_followValue = Math.Round(_followValue, 1);
                    _r_followValue = Convert.ToSingle(_d_followValue);
                    _lastDistance  = _distance;
                }
                _targetRotation   = listener.transform.rotation;
                _relativeRotation = Quaternion.Lerp(followEvent.transform.rotation, _targetRotation, _r_followValue);
                followEvent.transform.rotation = _relativeRotation;
            }

            if (isFollow)
            {
                followEvent.transform.rotation = listener.transform.rotation;
            }

            followEvent.transform.position = amb_FollowCollider.ClosestPoint(listener.transform.position);
            followEvent.Set_Parameter(followEvent.isFollowParameterId, _r_followValue);
        }
    }
Esempio n. 3
0
    public void InitGlobe()
    {
        ScreenX = Screen.width;
        ScreenY = Screen.height;
        globe   = FindObjectOfType <Globe>();

        if (globe != null)
        {
            // Home city
            SphereCollider globeCollider = globe.GetComponentInChildren <SphereCollider>();
            Vector3        pointOnSphere = globeCollider.ClosestPoint(Camera.main.transform.position + Camera.main.transform.forward * 5.0f);
            Transform      newCity       = Instantiate(cityPrefab, pointOnSphere, Quaternion.identity);
            newCity.parent = globeCollider.transform;
        }
    }
    /// <summary>
    /// Executes the movement and limits the sphere's position.
    /// </summary>
    public void FixedUpdate()
    {
        // Limit the sphere's position
        Vector3 limitedPosition = _pitchBoundaryCollider.ClosestPoint(transform.position);

        limitedPosition.y  = 0.0f;
        transform.position = limitedPosition;

        if (_time_tracker >= _change_taget_interval)
        {
            MoveAround();
            _time_tracker = 0;
        }

        _time_tracker += Time.fixedDeltaTime;
    }
    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.tag != "Player")
        {
            return;
        }

        _closestPointOnOverride = overrideCollider.ClosestPoint(listener.transform.position);
        _distance = Vector3.Distance(_closestPointOnOverride, listener.transform.position);
        if (_distance != _lastDistance)
        {
            Debug.Log(_distance);

            //SetGlobalOverride();
            _lastDistance = _distance;
        }
    }
Esempio n. 6
0
    public override void Do()
    {
        Mesh mesh = Instantiate(meshFilter.sharedMesh);

        Color[] meshColors = mesh.colors;
        if (meshColors == null || meshColors.Length != mesh.vertexCount)
        {
            meshColors = new Color[mesh.vertexCount];
            for (int i = 0; i < mesh.vertexCount; i++)
            {
                meshColors[i] = defaultColor;
            }
        }
        for (int i = 0; i < mesh.vertexCount; i++)
        {
            MeshExtensions.MeshVertex meshVertex = new MeshExtensions.MeshVertex(mesh, trs, i, null);
            if (sphereCollider.ClosestPoint(meshVertex.point) == meshVertex.point)
            {
                if (paintType == PaintType.Both || paintType == PaintType.Inside)
                {
                    meshColors[i] = insideSphereColor;
                }
            }
            else if (paintType == PaintType.Both || paintType == PaintType.Outside)
            {
                meshColors[i] = outsideSphereColor;
            }
        }
        mesh.colors           = meshColors;
        meshFilter.sharedMesh = mesh;
        if (makeAsset)
        {
            if (autoNameAssetPath)
            {
                string newAssetPath = saveAssetAtPath;
                while (File.Exists(newAssetPath))
                {
                    newAssetPath = newAssetPath.Replace(".asset", "1.asset");
                }
            }
            AssetDatabase.CreateAsset(meshFilter.sharedMesh, saveAssetAtPath);
            AssetDatabase.SaveAssets();
        }
    }
Esempio n. 7
0
    private void Update()
    {
        if (connectedPlayer != null)
        {
            float dist = Vector3.Distance(connectedPlayer.transform.position, transform.position);
            if (connectedPlayer.rigidbody.velocity.magnitude > 5f)
            {
                transform.position = Vector3.Lerp(transform.position, connectedPlayer.transform.position + connectedPlayer.rigidbody.velocity * 5, Time.deltaTime * 3.5f);
            }
            if (dist > col.radius)
            {
                transform.position = col.ClosestPoint(transform.position);
            }
        }
        transform.position = new Vector3(transform.position.x, 1.7f, transform.position.z);

        rot.eulerAngles    = new Vector3(90, 0, 0);
        transform.rotation = rot;
    }
Esempio n. 8
0
    void MoveEyeball()
    {
        if (target == null)
        {
            return;
        }

        //find vector on sphere to draw the pointer
        Vector3 position = sphereCollider.ClosestPoint(target.transform.position);

        // Debug.Log("Position " + position);
        position.z = -1;

        float angle = Vector3.Angle(sphereCollider.transform.position, target.transform.position);


        eyeball.transform.position = position;
        //    Debug.DrawRay(transform.position, target.transform.position);
    }
Esempio n. 9
0
    // Update is called once per frame
    void Update()
    {
        if (Radio.activeSelf)
        {
            agent.SetDestination(Radio.transform.position);
            if (radioIsInRange)
            {
                Debug.Log("Radio is in range");
            }
        }

        else if (flareIsInRange)
        {
            agent.SetDestination(Flare.transform.position);
            if (flareIsInRange)
            {
                Debug.Log("Flare is in range");
            }
        }

        else if (playerIsInRange)
        {
            agent.SetDestination(Player.transform.position);
        }

        else if (!playerIsInRange)
        {
            SphereCollider sc    = Player.GetComponent <SphereCollider>();
            Vector3        scpos = sc.ClosestPoint(this.transform.position);
            agent.SetDestination(scpos);
            agent.speed = locateSpeed;
        }


        //Could have made a class instead of messing with bools but what gives...
    }
Esempio n. 10
0
    public void OnTriggerPressed(object sender, ClickedEventArgs e)
    {
        PistolCharge pistolCharge = GetComponent <PistolCharge>();

        if (pistolCharge != null && pistolCharge.isActiveAndEnabled)
        {
            if (pistolCharge.currentShots < 1)
            {
                return;
            }
            pistolCharge.currentShots -= 1.0f;
        }

        PistolTarget closestPistolTarget = null;
        float        closestDistance     = float.PositiveInfinity;
        Vector3      pointOnTarget       = Vector3.zero;

        foreach (PistolTarget pistolTarget in PistolTarget.instances)
        {
            SphereCollider targetSphere = pistolTarget.sphereCollider;

            Vector3 targetPosition      = targetSphere.transform.TransformPoint(targetSphere.center);
            Vector3 localTargetPosition = muzzleTransform.InverseTransformPoint(targetPosition);

            float distanceMuzzleToTargetSphere = localTargetPosition.magnitude;
            if (distanceMuzzleToTargetSphere > 0) // else division by zero
            {
                var   angleToTarget          = Vector3.Angle(localTargetPosition, Vector3.forward);
                float additionalSlackDegrees = Mathf.Atan(targetSphere.radius / distanceMuzzleToTargetSphere) * Mathf.Rad2Deg;
                if (angleToTarget <= aimBotMaxAngleDegrees + additionalSlackDegrees)
                {
                    // ok, target is in viewcone of weapon's aimbot

                    Vector3 pointNearTarget = muzzleTransform.position + muzzleTransform.forward * Mathf.Max(distanceMuzzleToTargetSphere - targetSphere.radius, 0);
                    pointOnTarget = targetSphere.ClosestPoint(pointNearTarget); // this point would actually be shot at
                    Debug.DrawLine(muzzleTransform.position, pointOnTarget, Color.green);

                    RaycastHit raycastHit;
                    if (Physics.Raycast(muzzleTransform.position, (pointOnTarget - muzzleTransform.position).normalized, out raycastHit, float.MaxValue, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Collide))
                    {
                        if (raycastHit.collider == targetSphere)
                        {
                            // ok, line of sight is free

                            closestDistance     = localTargetPosition.magnitude;
                            closestPistolTarget = pistolTarget;
                        }
                    }
                }
            }
        }

        Vector3 shotDirection;

        if (closestPistolTarget != null)
        {
            Debug.DrawLine(muzzleTransform.position, pointOnTarget, Color.blue, 1.0f);
            shotDirection = (pointOnTarget - muzzleTransform.position).normalized;

            closestPistolTarget.Hit();
        }
        else
        {
            shotDirection = muzzleTransform.forward;
        }

        if (muzzleFlashPrefab != null)
        {
            Instantiate(muzzleFlashPrefab, muzzleTransform.position, muzzleTransform.rotation);
        }

        {
            RaycastHit raycastHit;
            if (Physics.Raycast(muzzleTransform.position, shotDirection, out raycastHit, float.MaxValue, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Collide))
            {
                if (bulletImpactPrefab != null && closestPistolTarget == null)
                {
                    Instantiate(bulletImpactPrefab, raycastHit.point, Quaternion.FromToRotation(Vector3.forward, raycastHit.normal), raycastHit.transform);
                }

                if (volumetricLineBehaviorPrefab != null)
                {
                    var volumetricLineBehavior = Instantiate(volumetricLineBehaviorPrefab);
                    volumetricLineBehavior.StartPos = muzzleTransform.position / volumetricLineBehaviorPrefab.transform.localScale.x;
                    volumetricLineBehavior.EndPos   = raycastHit.point / volumetricLineBehaviorPrefab.transform.localScale.x;
                }
            }
        }
    }
Esempio n. 11
0
 /// <summary>Get the point on the surface of the SphereCollider that is closest to the given point (ALL in world space).</summary>
 /// <param name="sphereCollider">The sphere collider to find the closest point on</param>
 /// <param name="targetPointWorldSpace">The point in world space that is the search guide</param>
 /// <returns>A vertex in world space</returns>
 public static Vector3 FindClosestSphereColliderVertex(SphereCollider sphereCollider, Vector3 targetPosWorldSpace)
 {
     return(sphereCollider.ClosestPoint(targetPosWorldSpace));
 }
    private void OnTriggerEnter(Collider other)
    {
        int layer = other.gameObject.layer;

        if (layer == LayerManager.SpriteLayer || layer == LayerManager.ProjectileLayer)
        {
            Vector3    diff = transform.position - other.transform.position;
            RaycastHit hitInfo;
            Vector3    contactPosition = other.Raycast(new Ray(other.transform.position - diff * 2, diff), out hitInfo, diff.magnitude * 2) ? hitInfo.point : _collider.ClosestPoint(other.transform.position);
            if (++_hitIndex == 4)
            {
                _hitIndex = 0;
            }
            _hits.SetRow(_hitIndex, transform.InverseTransformPoint(contactPosition));
            _hitAreaStartTimes[_hitIndex] = Time.time;
        }
    }
    /// <summary>
    /// Constrains the position of the mouse to the pitch's boundaries. Also, it processes the blink's cooldown.
    /// </summary>
    protected void FixedUpdate()
    {
        // Limit the agent's position
        Vector3 limitedPosition = _pitchBoundaryCollider.ClosestPoint(transform.position);

        limitedPosition.y  = _agentHeight;
        transform.position = limitedPosition;

        if (_allowChanges)
        {
            // Process blink cooldown
            if (_currentBlinkCooldown > 0)
            {
                _currentBlinkCooldown--;
            }
            else if (_currentBlinkCooldown == 0)
            {
                _renderer.material = _blinkReadyMaterial;
            }

            // Process character movement
            if (_destinationSet)
            {
                if (Vector3.Distance(transform.position, _destination) <= 0.1f)
                {
                    // Decrease velocity once the target is being approached
                    _currentArrivalSpeed = 0.1f;
                }
                else
                {
                    // Normal movement speed
                    _currentArrivalSpeed = 1.0f;
                }

                if (Vector3.Distance(_characterTransform.position, _destination) > 0.01f)
                {
                    // Move
                    if (!_isSlowed)
                    {
                        _characterRigidbody.velocity = (_destination - _characterTransform.position).normalized * _characterMovementSpeed * _currentArrivalSpeed;
                    }
                    // If the character is inside the slow sphere, decrease the character's movement speed relatively to the distance of the center of the sphere.
                    else
                    {
                        Vector3 charPos = _characterTransform.position;
                        charPos.y = 0.0f;
                        float distance          = (Vector3.Distance(charPos, _slowSphere.transform.position) / (_slowSphere.transform.localScale.y / 2.0f));
                        float relativeSlowRatio = Mathf.Clamp(distance, _slowSphere.SlowRatio, 1.0f);
                        _characterRigidbody.velocity = ((_destination - _characterTransform.position).normalized * _characterMovementSpeed * _currentArrivalSpeed) * relativeSlowRatio;
                    }
                }
                else
                {
                    // Stop
                    _characterTransform.position = _destination;
                    _destinationSet = false;
                    _characterRigidbody.velocity = Vector3.zero;
                }
            }
            else
            {
                _characterRigidbody.velocity = Vector3.zero;
            }
        }

        // Rotate towards movement direction
        if (_lookDirection != Vector3.zero)
        {
            _characterTransform.rotation = Quaternion.RotateTowards(_characterTransform.rotation, Quaternion.LookRotation(_lookDirection), _characterRotationSpeed);
        }
    }