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 库中 GameEntity 类的方法之一。该方法用于检测两个实体之间是否存在相互可见的线。

语法

lineOfSightTest( entity: GameEntity, options?: object ): boolean

参数

  • entity (必需):要检测可见性的目标实体。
  • options (可选):一个包含可选参数的对象。

可选参数

  • ignoreSelf:一个布尔值,表示是否忽略当前实体的可见性。默认值为 true
  • ignoreTarget:一个布尔值,表示是否忽略目标实体的可见性。默认值为 false

返回值

  • 如果两个实体之间存在相互可见的线,则返回值为 true
  • 如果两个实体之间不存在相互可见的线,则返回值为 false

示例

import { GameEntity } from 'yuka';

const entity1 = new GameEntity();
const entity2 = new GameEntity();

entity1.position.set( 0, 0, 0 );
entity2.position.set( 1, 1, 1 );

const lineOfSightExists = entity1.lineOfSightTest( entity2 ); // true
import { GameEntity } from 'yuka';

const entity1 = new GameEntity();
const entity2 = new GameEntity();

entity1.position.set( 0, 0, 0 );
entity2.position.set( 1, 1, 1 );

const lineOfSightExists = entity1.lineOfSightTest( entity2, { ignoreSelf: false, ignoreTarget: true } ); // false

注意事项

  1. lineOfSightTest() 方法只检测两个实体之间是否存在相互可见的线,不会考虑其他因素,例如阻挡物等。应该在使用前考虑是否适合。
  2. 在某些情况下,可能需要在执行此方法之前先为实体的位置属性更新(例如移动)。