ClosestPointOnBounds() public method

The closest point to the bounding box of the attached collider.

public ClosestPointOnBounds ( Vector3 position ) : Vector3
position Vector3
return Vector3
 void OnTriggerEnter(Collider other)
 {
     if(attack!=null){
         if(other.tag.Equals("Enemy")){
             attack.GetComponent<Attack>().enemyCollisionEnter(other.gameObject,other.ClosestPointOnBounds(transform.position));
         }else{
             attack.GetComponent<Attack>().otherCollisionEnter(other.gameObject,other.ClosestPointOnBounds(transform.position));
         }
     }
     if (debug != null) {
         debug.SetActive (true);
         wasEnabled = false;
     }
 }
 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Enemy") {
         IAController enemy = other.GetComponent<IAController>();
         enemy.getHurt(damage,other.ClosestPointOnBounds(transform.position),true);
     }
 }
 static public int ClosestPointOnBounds(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.Collider self = (UnityEngine.Collider)checkSelf(l);
         UnityEngine.Vector3  a1;
         checkType(l, 2, out a1);
         var ret = self.ClosestPointOnBounds(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Exemplo n.º 4
0
    //
    // DOWN
    //
    public void OnTriggerEnterDown( Collider lockCollider,Collider other )
    {
        if ( downLock > 0 && findNearestCollider( other, whoDown ) )
        {
            if ( other.transform.position.x == whoDown.transform.position.x )
            {
                downLock = LOCK_TIME;
                return;
            }
        }

        //		if ( downLock > 0 )
        //			return;
        //
        //		if ( posDelta.z < 0 )
        {
            downLock = LOCK_TIME;
            whoDown = other;

            Vector3 up = other.ClosestPointOnBounds( target.position + (Vector3.forward * 100) );
            float dif =   (lockCollider.transform.position.z - lockCollider.bounds.extents.z) - up.z;
            downLimitZ =  target.position.z - dif;// - offset.z;// - dif;//(transform.position.x - (lockCollider.transform.position.x + lockCollider.bounds.extents.x)) + lockCollider.transform.localPosition.x;
            debugSelect[3] = other.gameObject;

        }
    }
 void OnTriggerStay(Collider collider)
 {
     if(collider.gameObject.layer.Equals(LayerMask.NameToLayer("Player")) && cooldownTimer>cooldown && isActiveAndEnabled){
         cooldownTimer = 0f;
         GameManager.playerController.getHurt(damage,collider.ClosestPointOnBounds(transform.position));
     }
 }
Exemplo n.º 6
0
    public void HandleResource( Collider plantColl )
    {
        GameObject plant = plantColl.gameObject;
        if ( critter.gameObject.CompareTag("Herbivore") )  // Are we a Herbivore?
        {
            // Debug.Log("Weve hit a Plant!" + critter.ID.ToString());
            foreach ( int preyID in critter.preyList )
            {
                // Debug.Log("Looking for " + preyID.ToString() + " in " + plant.name);
                if ( plant.name.Contains( preyID.ToString() ) )
                {
                    if ( Random.value < .80f )
                    {
                        // Debug.Log("" + critter.ID.ToString() + " Nomm nomm " + plant.name);
                        critter.navMeshAgent.Stop();

                        Vector3 foragePoint = plantColl.ClosestPointOnBounds(critter.transform.position);
                        critter.navMeshAgent.SetDestination(foragePoint);
                        critter.navMeshAgent.Resume();
                        ToForageState();
                    }
                }
            }
        }
    }
Exemplo n.º 7
0
    void OnTriggerEnter(Collider other)
    {
        ObstaclePropertyInfo infoScript = other.gameObject.GetComponent<ObstaclePropertyInfo>();

        //如果進入Trigger物件無ObstaclePropertyinfo ,則離開此函式
        if (infoScript == null)
            return;

        //確認角色本身是否對應正確的障礙物
        if (this.ObstacleList.Contains(infoScript.Obstacle))
        {
            infoScript.CheckObstacle(true);
        }
        else
        {
            //創建 撞擊特效BoneAnimation
            SmoothMoves.BoneAnimation obj = (SmoothMoves.BoneAnimation)Instantiate(GameManager.script.EffectAnimationObject);
            obj.mLocalTransform.position = other.ClosestPointOnBounds(this.transform.position) - Vector3.forward;
            obj.playAutomatically = false;
            //隨機撥放 1 或 2 動畫片段
            if (Random.Range(0, 2) == 0)
                obj.Play("撞擊特效01");
            else
                obj.Play("撞擊特效02");

            infoScript.CheckObstacle(false);
            //給予角色傷害
            this.roleInfo.DecreaseLife(infoScript.Damage);
        }
    }
    void OnTriggerEnter(Collider other)
    {
        // 怪物必須未死亡
        if (!this.enemyInfo.isDead)
        {
            //撞擊角色並造成角色傷害
            if (((1 << other.gameObject.layer) & this.AttackLayer.value) > 0)
            {
                //tag = MainBody
                if (other.collider.tag.CompareTo("MainBody") == 0)
                {
                    //創建 撞擊特效BoneAnimation
                    SmoothMoves.BoneAnimation obj = (SmoothMoves.BoneAnimation)Instantiate(GameManager.script.EffectAnimationObject);
                    obj.mLocalTransform.position = other.ClosestPointOnBounds(this.transform.position) - Vector3.forward;
                    obj.playAutomatically = false;
                    //隨機撥放 1 或 2 動畫片段
                    if (Random.Range(0, 2) == 0)
                        obj.Play("撞擊特效01");
                    else
                        obj.Play("撞擊特效02");

                    //給予角色傷害
                    other.GetComponent<RolePropertyInfo>().DecreaseLife(enemyInfo.damage);
                }
            }
        }
    }
Exemplo n.º 9
0
    void OnTriggerEnter(Collider c)
    {
        int			i;
        GameObject	tmp;

        if (c.gameObject.tag == "enemy" && player != null && player.attacking)
        {
            enemy en = c.gameObject.GetComponentInParent<enemy>();
            if (en != null && !en.dead)
            {
                stats e = en.st;
                if (e != null)
                {
                    if (player.st.hitChance(e))
                    {
                        i = Random.Range(0, player.bloodEffects.Length);
                        tmp = (GameObject)Instantiate(player.bloodEffects[i], c.ClosestPointOnBounds(player.inv.equipedItems[0].transform.position), Quaternion.identity);
                        tmp.SetActive(true);
                        player.slashSounds[Random.Range(0, player.slashSounds.Length)].Play();
                        int dmg = player.st.finalDamage(e) + ist.finalDamage(e);
                        e.hp -= dmg;
                        if (e.hp <= 0)
                            e.hp = 0;
                        tmp = (GameObject)Instantiate(player.textPop, c.ClosestPointOnBounds(player.inv.equipedItems[0].transform.position), Quaternion.identity);
                        tmp.SetActive(true);
                        tmp.transform.LookAt(player.cam.transform.position);
                        tmp.transform.eulerAngles = new Vector3(tmp.transform.eulerAngles.x, tmp.transform.eulerAngles.y + 180, tmp.transform.eulerAngles.z);
                        textPop tp = tmp.GetComponent<textPop>();
                        tp.addConfig(dmg.ToString());
                        tp.addConfig(new Color(1.0f, 1.0f, 1.0f, 1.0f), 0.25f, 20.0f);
                        tp.addConfig(new Vector3(0.0f, 1.0f, 0.0f), 2.0f);
                    }
                    else
                    {
                        tmp = (GameObject)Instantiate(player.textPop, c.ClosestPointOnBounds(player.inv.equipedItems[0].transform.position), Quaternion.identity);
                        tmp.SetActive(true);
                        tmp.transform.LookAt(player.cam.transform.position);
                        tmp.transform.eulerAngles = new Vector3(tmp.transform.eulerAngles.x, tmp.transform.eulerAngles.y + 180, tmp.transform.eulerAngles.z);
                        textPop tp = tmp.GetComponent<textPop>();
                        tp.addConfig("miss");
                        tp.addConfig(new Color(1.0f, 1.0f, 1.0f, 1.0f), 0.25f, 20.0f);
                        tp.addConfig(new Vector3(0.0f, 1.0f, 0.0f), 2.0f);
                    }
                }
            }
        }
    }
Exemplo n.º 10
0
 void OnTriggerStay(Collider coll)
 {
     if(coll.gameObject.tag == "Player")
     {
         dir = coll.ClosestPointOnBounds(coll.gameObject.transform.position);
         rb.AddForceAtPosition(Vector3.down * power * Time.deltaTime, dir);
     }
 }
Exemplo n.º 11
0
 // Use this for trigger event
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject == player)
     {
         playerInRange = true;
         collisionPoint = other.ClosestPointOnBounds(transform.position);
     }
 }
Exemplo n.º 12
0
 void OnTriggerEnter(Collider collider)
 {
     if(collider.gameObject.layer == LayerMask.NameToLayer("Player")){
         parentAttack.enemyCollisionEnter (collider.gameObject,collider.ClosestPointOnBounds(transform.position));
         Destroy(gameObject);
     }else if(collider.gameObject.layer == LayerMask.NameToLayer("Planets")){
         Destroy(gameObject);
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// If the portal is inside the ground, it will be pushed out.
 /// </summary>
 void OnTriggerStay(Collider collider)
 {
     if (collider.tag == "Ground")
     {
         Vector3 distanceNormal = transform.position - collider.ClosestPointOnBounds(transform.position);
         distanceNormal.Normalize();
         transform.position += distanceNormal * 0.02f;
     }
 }
 void OnTriggerEnter(Collider hit)
 {
     if(hit.gameObject.tag == "Player")
     {
         Vector3 direction = hit.ClosestPointOnBounds(this.transform.position);
         hit.gameObject.GetComponent<Character>().knockBack(direction);
         hit.gameObject.GetComponent<Character>().takeDamage(10,this.gameObject);
     }
 }
Exemplo n.º 15
0
 void OnTriggerStay(Collider coll)
 {
     if (transform.rotation.y <= slope)
     {
         rb.constraints = RigidbodyConstraints.None;
         //플레이어와 접촉 되어 있는 부분에서 아래로 힘을 가함
         dir = coll.ClosestPointOnBounds(coll.gameObject.transform.position);
         rb.AddForceAtPosition(-Vector3.up * power * Time.deltaTime, dir);
     }
     else { rb.constraints = RigidbodyConstraints.FreezeRotation; }
 }
Exemplo n.º 16
0
	void OnTriggerEnter(Collider coll)
	{
		print (1);
		if (coll.gameObject.tag == "Player") {
			print (2);
			GameObject bump = Instantiate (bumpEmitter) as GameObject;
			bump.transform.position = coll.ClosestPointOnBounds(transform.position);
			bump.audio.Play();
			Destroy (bump,5);
		}
	}
  void OnTriggerEnter(Collider other) {
    if(PropulsionPadActive()) {
      //////////////////////////////////////////////////////////////////
      // To prevent the collider from missing the target, get the
      // closest point the collider hit on the trigger and calculate the
      // velocity based on that starting point.
      Vector3 hitPoint = other.ClosestPointOnBounds(transform.position);
      PropelObject(other.gameObject, CalculateVelocity(hitPoint));
		
    }
  }
 void OnTriggerStay(Collider other)
 {
     if(other.gameObject.tag == "Laser" && !laserHitCooldown){
         Vector3 hitLocation = other.ClosestPointOnBounds(gameObject.transform.position);
     //			Debug.Log(hp);
         hp--;
         Object bulletExpl = Instantiate(bulletHit,hitLocation,other.transform.rotation);
         Destroy(bulletExpl,2);
         Invoke("ActivateLaser", 0.01f);
         laserHitCooldown = true;
     }
 }
	void OnTriggerStay(Collider Other){
		if(nearest[0]==Other)
		{
			Vector3 point = Other.ClosestPointOnBounds(emitStart.transform.position);
			Vector3 relative = point-emitStart.transform.position;
			float angle = Vector3.Angle(relative,transform.forward)/180*Mathf.PI;
			Vector3 project = transform.forward*Mathf.Abs(relative.magnitude/Mathf.Cos(angle));
			Vector3 middle = project/2+emitStart.transform.position;
			float temp = project.magnitude/2;
			light.transform.localScale = new Vector3(light.transform.localScale.x,light.transform.localScale.y,temp);
			light.transform.position = middle;
		}
	}
Exemplo n.º 20
0
 static public int ClosestPointOnBounds(IntPtr l)
 {
     try {
         UnityEngine.Collider self = (UnityEngine.Collider)checkSelf(l);
         UnityEngine.Vector3  a1;
         checkType(l, 2, out a1);
         var ret = self.ClosestPointOnBounds(a1);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 21
0
	void OnTriggerEnter (Collider other)
	{
		if(other.isTrigger)
			return;
		if(other.gameObject.tag == "Untagged" || other.gameObject.tag == "Terrain")
		{
			if(isRunning)
			{
				// Create a dust particle since our foot touched the ground and we
				// are running.
				// You could have a sound play here as well. I didn't have any.
				Manager_Particle.instance.CreateParticle(other.ClosestPointOnBounds(transform.position), ParticleTypes.Dust_Run, 1);
			}
		}
	}
Exemplo n.º 22
0
 static int QPYX_ClosestPointOnBounds_YXQP(IntPtr L_YXQP)
 {
     try
     {
         ToLua.CheckArgsCount(L_YXQP, 2);
         UnityEngine.Collider QPYX_obj_YXQP  = (UnityEngine.Collider)ToLua.CheckObject <UnityEngine.Collider>(L_YXQP, 1);
         UnityEngine.Vector3  QPYX_arg0_YXQP = ToLua.ToVector3(L_YXQP, 2);
         UnityEngine.Vector3  QPYX_o_YXQP    = QPYX_obj_YXQP.ClosestPointOnBounds(QPYX_arg0_YXQP);
         ToLua.Push(L_YXQP, QPYX_o_YXQP);
         return(1);
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
Exemplo n.º 23
0
	void OnTriggerEnter(Collider other) {
		if (other.gameObject.GetComponent<Stair>()) {
			stair = other;
		} else if (other.gameObject.GetComponent<Floor>()) {
			Debug.Log ("floor");
			floor = other;
			Collider myCol = GetComponent<Collider>();
			Vector3 pos = transform.position; // Turn it into a variable
			
			if(myCol.bounds.min.y > other.transform.position.y)
				;
//				pos.y = other.bounds.max.y + transform.localScale.y / 2;
			else
			{
				Vector3 closest = other.ClosestPointOnBounds(transform.position);
				float relx = (closest.x - other.bounds.min.x) / other.bounds.size.x;
				float rely = (closest.y - other.bounds.min.y) / other.bounds.size.y;
				float relxOpp = 1.0F - relx;
				float relyOpp = 1.0F - rely;
				
				if (relx < rely && relx < relxOpp && relx < relyOpp)
				{
					// Left
					pos.x = other.bounds.min.x - transform.localScale.x / 2;
				}
				else if (rely < relxOpp && rely < relyOpp)
				{
					// Bottom
					//sidePlatform = other;
					pos.y = other.bounds.min.y - transform.localScale.y / 2;
				}
				else if (relxOpp < relyOpp)
				{
					// Right
					//sidePlatform = other;
					pos.x = other.bounds.max.x + transform.localScale.x / 2;
				}
				else
				{
					// Top
					pos.y = other.bounds.max.y + transform.localScale.y / 2;
				}
			}
			velocity.y = 0.0F;
			transform.position = pos;
		}
		velocity = Vector3.zero;
	}
 static int ClosestPointOnBounds(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.Collider obj  = (UnityEngine.Collider)ToLua.CheckObject(L, 1, typeof(UnityEngine.Collider));
         UnityEngine.Vector3  arg0 = ToLua.ToVector3(L, 2);
         UnityEngine.Vector3  o    = obj.ClosestPointOnBounds(arg0);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 25
0
    public virtual void OnTriggerEnter(Collider other) 
	{
        if (other.gameObject.layer == playerLayer && collideWithPlayer) {
            bool collide = true;
            if (canRunOnTop) {
                if (Vector3.Dot(Vector3.up, (other.transform.position - thisTransform.position)) > 0) {
                    collide = false;
                    thisGameObject.layer = platformLayer;
                    playerAnimation.run();
                }
            }

            if (collide) {
                gameManager.obstacleCollision(this, other.ClosestPointOnBounds(thisTransform.position));
            }
		}
	}
Exemplo n.º 26
0
    void Attack(Collider other)
    {
        if (combatSelf == null)
            return;
        //combatSelf.isAttacking && self.GetComponent<AIStates>() ||
        if (combatSelf.isAttacking){
            //Unit pOther = other.GetComponent<Unit>();
            //AIPathCustom pOther = other.GetComponent<AIPathCustom>();

            ICombat combatOther = other.GetComponent(typeof(ICombat)) as ICombat;
            if (combatOther == null){return;}
            if (combatSelf.FactionHostile.Count > 0 && BattleCore.isHostile(combatSelf.FactionHostile,combatOther.FactionSelf)){
                combatSelf.onAttack(other.ClosestPointOnBounds(other.transform.position));
                combatOther.hurt(combatSelf.Weapon);
                //combatOther.AddImpact((other.transform.position - this.transform.position),500);
            }
        }
    }
Exemplo n.º 27
0
    void OnTriggerEnter(Collider other)
    {
        if (!this.isExplosion)
        {
            if (((1 << other.collider.gameObject.layer) & this.ExplosiveLayer.value) > 0)   //判定爆炸的Layer
            {
                if (other.collider.tag.CompareTo("MainBody") == 0)
                {
                    //如對象為敵人,需再檢查敵人本身是否已經死亡(EnemyPropertyInfo.isDead)
                    if (other.gameObject.layer == LayerMask.NameToLayer("Enemy"))
                    {
                        if (other.GetComponent<EnemyPropertyInfo>().isDead)
                            return;
                    }
                    else if (other.gameObject.layer == LayerMask.NameToLayer("Boss"))
                    {
                        if (other.GetComponent<BossPropertyInfo>().isDead)
                            return;
                    }

                    //以下產生爆炸事件
                    this.isExplosion = true;

                    //爆炸中心為Collider交錯點
                    Vector3 expPos = other.ClosestPointOnBounds(this.transform.position);
                    expPos.z = other.gameObject.transform.position.z - 1;
                    this.boneAnimation.mLocalTransform.position = expPos;

                    this.boneAnimation.Play("explosion");

                    //移除Script,使爆炸位置固定、換圖正常
                    Destroy(this.GetComponent<MoveController>());

                    //處理不同碰撞物的部分(小怪、魔王、遊戲角色)
                    if (other.gameObject.layer == LayerMask.NameToLayer("Enemy"))
                        other.GetComponent<EnemyPropertyInfo>().DecreaseLife(this.Damage);
                    else if (other.gameObject.layer == LayerMask.NameToLayer("Boss"))
                        other.GetComponent<BossPropertyInfo>().DecreaseLife(this.Damage);
                    else if (other.gameObject.layer == LayerMask.NameToLayer("Role"))
                        other.GetComponent<RolePropertyInfo>().DecreaseLife(this.Damage);
                }
            }
        }
    }
    static int ClosestPointOnBounds(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("UnityEngine.Collider.ClosestPointOnBounds");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 2);
            UnityEngine.Collider obj  = (UnityEngine.Collider)ToLua.CheckObject <UnityEngine.Collider>(L, 1);
            UnityEngine.Vector3  arg0 = ToLua.ToVector3(L, 2);
            UnityEngine.Vector3  o    = obj.ClosestPointOnBounds(arg0);
            ToLua.Push(L, o);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemplo n.º 29
0
    public LayerMask ThroughLayer; //爆破的對象

    #endregion Fields

    #region Methods

    void OnTriggerEnter(Collider other)
    {
        if (((1 << other.collider.gameObject.layer) & this.ThroughLayer.value) > 0)   //判定爆炸的Layer
        {
            if (other.collider.tag.CompareTo("MainBody") == 0)
            {
                //如對象為敵人,需再檢查敵人本身是否已經死亡(EnemyPropertyInfo.isDead)
                if (other.gameObject.layer == LayerMask.NameToLayer("Enemy"))
                {
                    if (other.GetComponent<EnemyPropertyInfo>().isDead)
                        return;
                }
                else if (other.gameObject.layer == LayerMask.NameToLayer("Boss"))
                {
                    if (other.GetComponent<BossPropertyInfo>().isDead)
                        return;
                }

                //創建特效BoneAnimation
                SmoothMoves.BoneAnimation obj = (SmoothMoves.BoneAnimation)Instantiate(GameManager.script.EffectAnimationObject);

                //爆炸中心為Collider交錯點
                Vector3 expPos = other.ClosestPointOnBounds(this.transform.position);
                expPos.z = other.gameObject.transform.position.z - 1;
                obj.mLocalTransform.position = expPos;
                obj.playAutomatically = false;
                //this.boneAnimation.mLocalTransform.position = expPos;

                if (Random.Range(0, 2) == 0)
                    obj.Play("撞擊特效01");
                else
                    obj.Play("撞擊特效02");

                //處理不同碰撞物的部分(小怪、魔王、遊戲角色)
                if (other.gameObject.layer == LayerMask.NameToLayer("Enemy"))
                    other.GetComponent<EnemyPropertyInfo>().DecreaseLife(this.Damage);
                else if (other.gameObject.layer == LayerMask.NameToLayer("Boss"))
                    other.GetComponent<BossPropertyInfo>().DecreaseLife(this.Damage);
                else if (other.gameObject.layer == LayerMask.NameToLayer("Role"))
                    other.GetComponent<RolePropertyInfo>().DecreaseLife(this.Damage);
            }
        }
    }
Exemplo n.º 30
0
    void OnTriggerEnter(Collider other)
    {
        //disable projectile
        gameObject.SetActive(false);

        //place an explosion at collision point
        Vector3 hitDirection = other.ClosestPointOnBounds(transform.position);
        Instantiate(projectileExplosion, hitDirection, Quaternion.identity);

        //check whether collider was a rigidbody
        Rigidbody body = other.attachedRigidbody;

        //don't do anything if no non-kinematic rigidbody is found
        if (body == null || body.isKinematic)
            return;

        //place positional force on rigidbody
        Vector3 direction = body.transform.position - transform.position;
        body.AddForceAtPosition(direction.normalized * hitForce, transform.position);
    }
Exemplo n.º 31
0
  //Returns the closiest point to cur position on bounds of cld
  public static Vector3 CalcPointOnBounds( Collider cld, Vector3 cur )
  {
    SphereCollider sphc = cld as SphereCollider;

    if( !sphc )
      return cld.ClosestPointOnBounds( cur );
    else
    {
      //cld.ClosestPointOnBounds returns not precise values for spheres
      //Fortunately they could be calculated easily
      var realPos = sphc.transform.position + sphc.center;
      var dir = cur - realPos;
      var realScale = sphc.transform.lossyScale;
      var realRadius = sphc.radius * Mathf.Max( realScale.x, realScale.y, realScale.z );
      var dirLength = dir.magnitude;

      //BoxCollider.ClosestPointOnBounds returns cur if points are inside the volume
      if( dirLength < realRadius )
        return cur;

      var dirFraction = realRadius / dirLength;
      return realPos + dirFraction * dir;
    }
  }
Exemplo n.º 32
0
    void OnTriggerEnter(Collider other)
    {

        


        Animal e = other.GetComponent<Animal>();
        if (e)
        {

            if (!canBaby)
                return;

            if (GameManager.Instance.timeOfEggs <= 0.0f)
            {
                animal1 = transform;
                animal2 = other.transform;
                fusion(other.ClosestPointOnBounds(transform.position));
                GameManager.Instance.timeOfEggs = 15.0f;
            }


        }


    }
Exemplo n.º 33
0
	/// <summary>
	/// this method can be used to protect against general distance cheats
	/// (like sending an RPC to push a button when you're in fact nowhere
	/// near it). for example: can be called on the master to verify that a
	/// player is within range of an object that it wants to manipulate.
	/// by default the method will return true if the player is inside or
	/// less than 2 meters away from the bounding box of 'collider', and
	/// false if not
	/// </summary>
	public bool IsCloseTo(Collider otherCollider, float distance = 2)
	{

		distance = Mathf.Max(distance, Player.Radius.Get() + Controller.SkinWidth);

		if (Vector3.Distance(Collider.bounds.center, otherCollider.ClosestPointOnBounds(Collider.bounds.center)) < distance)
			return true;	// player is in proximity to, or touching the collider bounds

		if (otherCollider.bounds.Contains(Collider.bounds.center))
			return true;	// player center is inside collider bounds (addresses cases where the above
							// distance check might fail due to standing inside very large bounds)

		if (otherCollider.bounds.Contains(Collider.bounds.center - (Vector3.up * (Player.Height.Get() * 0.5f))))
			return true;	// player is standing on collider bounds

		if (otherCollider.bounds.Contains(Collider.bounds.center + (Vector3.up * (Player.Height.Get() * 0.5f))))
			return true;	// player head is touching collider bounds

		// player is not close to the collider
		return false;

	}
Exemplo n.º 34
0
    public Vector3 RelativeTopColliderPoint(Collider collider)
    {
        Vector3 worldTopPos = collider.transform.position + (Camera.main.transform.up * 5);

        return collider.ClosestPointOnBounds(worldTopPos);
    }
Exemplo n.º 35
0
 public void Update(Collider innerShell)
 {
     genPos += genVel * Time.deltaTime;
     farPoint.x = Mathf.Cos(genPos.y) * farRadius * Mathf.Cos(genPos.x);
     farPoint.y = Mathf.Sin(genPos.y) * farRadius * Mathf.Cos(genPos.x);
     farPoint.z = Mathf.Sin(genPos.x) * farRadius;
     farPoint = innerShell.transform.TransformPoint(farPoint);
     curPos = innerShell.ClosestPointOnBounds(farPoint);
     curPos = innerShell.transform.InverseTransformPoint(curPos);
     curPos *= genPos.z;
     if (genPos.z > outerShellWidth) {
         genVel.z = -Mathf.Abs(genVel.z);
     }
     else if (genPos.z < innerShellWidth) {
         genVel.z = Mathf.Abs(genVel.z);
     }
 }