PointEntity entity,target[,roll#]
Parameters
|
entity - entity handle target - target entity handle roll# (optional) - roll angle of entity; 0 (default) |
Description
|
Points one entity at another. The entity is rotated so that its z axis (its 'forward' direction) faces the target entity. Pointing only sets the pitch and yaw angles; the optional roll parameter lets you set the roll as well. This is the quick way to aim things: turrets tracking the player, homing missiles, a camera locked onto the action, an enemy turning to face its victim. Point once for a snap turn; for a smooth turn, read the angles the entity would need (using DeltaPitch/DeltaYaw) and turn a little each frame instead. If you want an entity to point at a position rather than at another entity, create a pivot at the desired position, point the entity at the pivot, then free the pivot. See also: AlignToVector, RotateEntity, DeltaPitch, DeltaYaw, CreatePivot. |
Example
; PointEntity Example ; ------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,2,-10 light=CreateLight() RotateEntity light,45,45,0 ; A turret barrel (long in z, the "forward" axis that PointEntity aims) barrel=CreateCube() ScaleMesh barrel,0.2,0.2,1 EntityColor barrel,255,255,0 ; A drone that flies loops around the turret drone=CreateSphere(8) ScaleEntity drone,0.4,0.4,0.4 EntityColor drone,0,255,0 angle#=0 While Not KeyDown(1) ; Fly the drone in a weaving circle angle=angle+1 PositionEntity drone,Cos(angle)*4,Sin(angle*3),Sin(angle)*4 ; Keep the turret barrel aimed at the drone PointEntity barrel,drone ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Arrow keys: move camera Esc: exit" Text 0,20,"PointEntity barrel,drone keeps the barrel aimed at the moving drone" Flip Wend End
Index