protected void DetectSurrounding()
    {
        Collider collider = aim.currentTarget;

        if (Owner == null || collider == null)
        {
            return;
        }

        CachedStickingObject = collider.gameObject.GetComponent <StickingObject>();
        CachedPlayer         = collider.gameObject.GetComponent <Player>();

        if (CachedStickingObject)
        {
            if (!CachedStickingObject.IsSticked)
            {
                ChasedObject = CachedStickingObject.gameObject.transform;
                Owner.SetChasedObject(ChasedObject.gameObject);
                Owner.ChangeFSMState(AIPlayerStates.CHASE);
            }
        }
        else if (CachedPlayer)
        {
            if (CachedPlayer != AIPlayer && AIPlayer.Type != CachedPlayer.Type)
            {
                ChasedObject = CachedPlayer.gameObject.transform;
                Owner.SetChasedObject(ChasedObject.gameObject);
                Owner.ChangeFSMState(AIPlayerStates.CHASE);
            }
        }
    }
    void SetToPool()
    {
        StickingObject stickingObject = Instantiate(prefabStickingObjet, transform.position, Quaternion.identity);

        stickingObject.Factory = this;

        int          materialRandom = Random.Range(0, materials.Length);
        Material     material       = materials[materialRandom];
        MeshRenderer mesh           = SetMeshChild(stickingObject, material);

        float       randomSize = Random.Range(.1f, 2f);
        ObjectStats stats      = new ObjectStats();

        stats.SetType((ObjectStats.Type)materialRandom);

        stats *= randomSize;
        stickingObject.SetObjectStats(stats);

        stickingObject.transform.localScale *= randomSize;

        stickingObject.transform.SetParent(transform);


        stickyQueue.Enqueue(stickingObject);
        stickingObject.gameObject.SetActive(false);
    }
 public void SetParent(MassObject ObjectParent, StickingObject stickingObjectParent)
 {
     sinRotation.Initialize();
     this.stickingObjectParent = stickingObjectParent;
     this.ObjectParent         = ObjectParent;
     size           = transform.localScale;
     rb.isKinematic = true;
 }
Example #4
0
    private void OnTriggerStay(Collider other)
    {
        StickingObject stickingObject = other.GetComponent <StickingObject>();

        if (stickingObject)
        {
            Attraction(stickingObject.rb);
        }
    }
Example #5
0
    public void CalculateDistanceCamera(StickingObject newStickingObject)
    {
        float newDistance = (newStickingObject.transform.position - player.transform.position).magnitude;

        if (newDistance > maxDistanceStickingObject)
        {
            SetNewDistance(newDistance);
        }
    }
    private MeshRenderer SetMeshChild(StickingObject stickingObject, Material material)
    {
        int          randomMeshIndex = Random.Range(0, meshPrefabs.Length);
        MeshRenderer meshModel       = Instantiate(meshPrefabs[randomMeshIndex], Random.insideUnitSphere * radiusSpawn, Quaternion.identity);

        meshModel.transform.SetParent(stickingObject.transform);
        meshModel.transform.localPosition = Vector3.zero;
        meshModel.material = material;
        stickingObject.SetMeshChild(meshModel.transform);
        return(meshModel);
    }
    public void DetatchFromParent()
    {
        transform.SetParent(null, true);
        ObjectParent         = null;
        stickingObjectParent = null;

        DetatchChilds();

        //testing
        rb.velocity        = (Random.insideUnitSphere * 2);
        rb.angularVelocity = (Random.insideUnitSphere * 5);
    }
    private void OnTriggerEnter(Collider collision)
    {
        StickingObject stickingObject = collision.transform.GetComponent <StickingObject>();

        if (stickingObject != null)
        {
            if (IsSticked && !stickingObject.IsSticked)
            {
                Debug.Log("collision");
                StickingNewChild(stickingObject);

                ShakeScale(impactBlobiness, this);
            }
        }
    }
    public void StickingNewChild(StickingObject stickingChild)
    {
        stickingChild.transform.SetParent(transform, true);

        stickingChild.SetParent(ObjectParent, this);

        stickingObjectChilds.Add(stickingChild);

        stickingChild.rb.velocity        = Vector3.zero;
        stickingChild.rb.angularVelocity = Vector3.zero;

        //PlayerParent.OnNewStickingObject.Invoke(this);

        AkSoundEngine.PostEvent("Stick", gameObject);
    }
    void SpawnObject()
    {
        StickingObject stickingObject = stickyQueue.Dequeue();

        if (stickingObject == null)
        {
            return;
        }

        stickingObject.GetComponent <HealthComponent>().Init();

        Rigidbody rigidBody = stickingObject.rb;

        rigidBody.velocity        = (Random.insideUnitSphere * vectorMagnitude);
        rigidBody.angularVelocity = (Random.insideUnitSphere * spinMagnitude);

        stickingObject.transform.position = Random.insideUnitSphere * radiusSpawn;

        stickingObject.gameObject.SetActive(true);
        listUsedStickyObject.Add(stickingObject);
    }
Example #11
0
    protected void AimTarget()
    {
        Collider collider = aim.currentTarget;

        if (chasedObject == null || collider == null)
        {
            return;
        }

        cachedStickingObject = collider.gameObject.GetComponent <StickingObject>();

        cachedPlayer = collider.gameObject.GetComponent <Player>();

        if (cachedStickingObject)
        {
            if (!cachedStickingObject.IsSticked)
            {
                if (Vector3.Distance(cachedStickingObject.transform.position, CachedTransform.position) < Vector3.Distance(chasedObject.position, CachedTransform.position))
                {
                    chasedObject = cachedStickingObject.gameObject.transform;
                    TimeElapsed  = 0;
                }
            }
        }
        else if (cachedPlayer)
        {
            if (cachedPlayer != AIPlayer && AIPlayer.Type != cachedPlayer.Type)
            {
                if (Vector3.Distance(cachedPlayer.transform.position, CachedTransform.position) < Vector3.Distance(chasedObject.position, CachedTransform.position))
                {
                    chasedObject = cachedPlayer.gameObject.transform;
                    TimeElapsed  = 0;
                }
            }
        }
    }
    public void ShakeScale(float impact, StickingObject objectToIgnore)
    {
        if (impact < 0.01)
        {
            return;
        }

        childMeshTransform.DOKill();
        //childMeshTransform.localScale = Vector3.one;
        childMeshTransform.DOShakeScale(1, impact, 20).OnComplete(ResetSizeWiggle);

        foreach (StickingObject stickingChild in stickingObjectChilds)
        {
            if (stickingChild != objectToIgnore)
            {
                stickingChild.ShakeScale(impact * impactPropagation, this);
            }
        }

        if (stickingObjectParent != null && stickingObjectParent != objectToIgnore)
        {
            stickingObjectParent.ShakeScale(impact * impactPropagation, this);
        }
    }
 public void DestroyObject(StickingObject stickingObject)
 {
     stickingObject.gameObject.SetActive(false);
     stickingObject.transform.SetParent(transform);
     stickyQueue.Enqueue(stickingObject);
 }