예제 #1
0
        // Check for geometry in the way (stairs,...)
        bool IsDirectionClear(MobileDirection direction)
        {
            Vector3 tempTargetScenePosition = cityNavigation.WorldToScenePosition(cityNavigation.NavGridToWorldPosition(GetNextNavPosition(direction)));

            // Aim low to better detect stairs
            tempTargetScenePosition.y += 0.1f;
            Ray  ray       = new Ray(transform.position, tempTargetScenePosition - transform.position);
            bool collision = Physics.Raycast(transform.position, tempTargetScenePosition - transform.position, Vector3.Distance(transform.position, tempTargetScenePosition), ~mobileAsset.GetLayerMask());

            // Debug.DrawRay(transform.position, tempTargetScenePosition - transform.position, collision ? Color.red : Color.green, 1f);
            return(!collision);
        }
예제 #2
0
        void SetTargetPosition()
        {
            // Get target position on navgrid and in world
            targetNavPosition   = GetNextNavPosition(currentDirection);
            targetWorldPosition = cityNavigation.NavGridToWorldPosition(targetNavPosition);

            // Get the target position in scene
            targetScenePosition = cityNavigation.WorldToScenePosition(targetWorldPosition);
            distanceToTarget    = 0;

            // Target point will be at ground level (roughly waist-level for mobile), so adjust up by half mobile height
            targetScenePosition.y += halfMobileHeight;

            // Mobile now owns target tile and can release current tile
            cityNavigation.ClearFlags(currentNavPosition, CityNavigation.TileFlags.Occupied);
            cityNavigation.SetFlags(targetNavPosition, CityNavigation.TileFlags.Occupied);

            // Change state to moving forwards
            ChangeState(MobileStates.MovingForward);
            seekCount = 0;
        }