AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

lineOfSightTest

概述

lineOfSightTest 是Yuka js库中Vehicle类的一个方法。该方法用于确定一个车辆是否能在两点之间看到目标。

语法

lineOfSightTest( target, options )

参数

  • target:类型为 Vector3 的目标点。
  • options:类型为 Object 的可选参数。包含以下属性:
    • testPoint:类型为 Vector3 的测试点。默认为车辆位置。
    • viewAngle:视角角度(以弧度为单位)。默认为 Math.PI / 4
    • viewDistance:视距。默认为 100
    • fov:视野对象。默认为一个由 new Cylindrical( 1, 1, 0.5 ) 创建的圆柱体。

返回值

  • 如果车辆可以看到目标,则返回 true
  • 如果车辆无法看到目标,则返回 false

示例

import { Vehicle, Vector3 } from 'yuka';

const vehicle = new Vehicle();

const point1 = new Vector3( 10, 0, 0 );
const point2 = new Vector3( 20, 0, 0 );
const target = new Vector3( 15, 0, 0 );

vehicle.position.set( 0, 0, 0 );

// 检测车辆是否能看到点1
const canSee1 = vehicle.lineOfSightTest( point1 );

// 检测车辆是否能看到点2
const canSee2 = vehicle.lineOfSightTest( point2 );

// 检测车辆是否能看到目标点
const canSeeTarget = vehicle.lineOfSightTest( target );

以上示例将创建一个车辆和三个点(点1、点2和目标点)。使用 lineOfSightTest 方法分别检测车辆是否可以看到这些点。