SamplePathPosition() 개인적인 메소드

private SamplePathPosition ( int areaMask, float maxDistance, NavMeshHit &hit ) : bool
areaMask int
maxDistance float
hit NavMeshHit
리턴 bool
예제 #1
0
	public bool PassingThrough(Vector4 plane) {
		UnityEngine.AI.NavMeshHit hit;
		navMeshAgent.SamplePathPosition(-1, 2.5f, out hit);
		if(hit.distance==0.0f) return false;

		Vector3 next_pos = hit.position;
		Vector3 curr_pos = transform.position;

		// Test positions are on opposite sides of door plane.
		float s1 = Vector3.Dot(next_pos, plane) + plane.w;
		float s2 = Vector3.Dot(curr_pos, plane) + plane.w;
		return s1*s2<0.0f;
	}
 static public int SamplePathPosition(IntPtr l)
 {
     try {
         UnityEngine.AI.NavMeshAgent self = (UnityEngine.AI.NavMeshAgent)checkSelf(l);
         System.Int32 a1;
         checkType(l, 2, out a1);
         System.Single a2;
         checkType(l, 3, out a2);
         UnityEngine.AI.NavMeshHit a3;
         var ret = self.SamplePathPosition(a1, a2, out a3);
         pushValue(l, true);
         pushValue(l, ret);
         pushValue(l, a3);
         return(3);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static int SamplePathPosition(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 4);
         UnityEngine.AI.NavMeshAgent obj = (UnityEngine.AI.NavMeshAgent)ToLua.CheckObject(L, 1, typeof(UnityEngine.AI.NavMeshAgent));
         int   arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
         UnityEngine.AI.NavMeshHit arg2;
         bool o = obj.SamplePathPosition(arg0, arg1, out arg2);
         LuaDLL.lua_pushboolean(L, o);
         ToLua.PushValue(L, arg2);
         return(2);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #4
0
    /// <summary>
    /// Update method.
    /// </summary>
    void Update()
    {
        // Check if the flash pedestrian is paused
        if (globalParam != null)
        {
            if (globalParam.flashPedestriansPaused && !isPause)
            {
                navAgent.speed = 0;
                isPause        = true;
            }
            else if (!globalParam.flashPedestriansPaused && isPause)
            {
                navAgent.speed = profile.speed;

                if (goingBikingToDestination)
                {
                    navAgent.speed += 3;
                }

                isPause = false;
            }
        }

        if (!isPause)
        {
            // Check the weather and update pedestrian behaviour accordingly
            if (currentWeather != flashInformer.globalParam.currentWeatherCondition)
            {
                ChangePedestrianBehaviourOnWeather(flashInformer.globalParam.currentWeatherCondition);
            }

            // If going to station, check if pedestrian has arrived to station
            if (goingToStation && Vector3.Distance(this.transform.position, nextPoint.position) < 4.0f)
            {
                // Arrives at the station
                goingToStation = false;
                FSM.SetBool("OnStation", true);
            }

            // If going to destination, check if pedestrian has arrived to destination
            if (goingToDestination && Vector3.Distance(transform.position, routing.destination.transform.position) < 4.0f)
            {
                // Arrives at the destination
                goingToDestination = false;
                FSM.SetBool("OnDestination", true);
            }

            // If going to take a bike, check if pedestrian has arrived to bike station
            if (takingABike && Vector3.Distance(this.transform.position, targetedBikeStation.transform.position) < 4.0f)
            {
                // Arrives at the bike station
                takingABike = false;
                FSM.SetBool("OnBikeStation", true);
            }

            // If going to take a bike an arrived and there is no bike station there, bike station has moved
            if (takingABike && (navAgent.remainingDistance < 3.0f || navAgent.isPathStale))
            {
                navAgent.ResetPath();
                navAgent.SetDestination(targetedBikeStation.transform.position);
            }

            // If going to destination biking, check if pedestrian has arrived to destination
            if (goingBikingToDestination && Vector3.Distance(this.transform.position, routing.destination.transform.position) < 4.0f)
            {
                // Arrives at the destination
                goingBikingToDestination = false;
                FSM.SetBool("OnDestination", true);
            }

            // If car awareness is active and pedestrian is walking or cycling, check if it is on a road
            if (profile.carAwareness && (goingToStation || goingToDestination || takingABike || goingBikingToDestination))
            {
                if (carAwarenessTimer > carAwarenessFrequency)
                {
                    UnityEngine.AI.NavMeshHit navHit;
                    if (navAgent.enabled && navAgent.hasPath && !navAgent.SamplePathPosition(-1, 2.0f, out navHit))
                    {
                        if ((navHit.mask & roadMask) != 0)
                        {
                            // Send message to the cars around
                            InformVehiclesAround();
                        }
                    }

                    carAwarenessTimer = 0.0f;
                }

                carAwarenessTimer += Time.deltaTime;
            }

            // If bikes are enabled, check if there are bike stations around
            if (flashInformer.globalParam.bikesEnabled && (!takingABike || !goingBikingToDestination))
            {
                // If the pedestrian is willing to take a bike, it will look for bike stations nearby.
                if ((goingToStation || goingToDestination) && bikeAwarenessTimer > bikeAwarenessFrequency &&
                    profile.chanceOfTakingABike + flashInformer.globalParam.percOfPedTakingBikes * profile.weatherFactorOnTakingBikes > 1.0f)
                {
                    targetedBikeStation = flashInformer.FindBikeStationNearby(this.transform.position);

                    if (targetedBikeStation != null && targetedBikeStation.capacityNumber > 0)
                    {
                        navAgent.enabled = false;
                        GoToBikeStation();
                    }

                    bikeAwarenessTimer = 0.0f;
                }

                bikeAwarenessTimer += Time.deltaTime;
            }
        }
    }