TurnToEntity

Blitz3D Forums/Blitz3D Programming/TurnToEntity

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

This might be what you're after ...

PointEntitySmooth()

Not my function. Got it from the code archives some time ago:

; PointEntitySmooth() - example

Graphics3D 640,480

cube=CreateCube()
ScaleMesh cube,1,1,2
EntityColor cube,100,100,100

pivot=CreatePivot()
sphere=CreateSphere( 16,pivot )
PositionEntity sphere,5,0,5

camera=CreateCamera()
PositionEntity camera,0,0,-14

light=CreateLight()
TurnEntity light,45,45,0

While Not KeyHit(1)
 TurnEntity pivot,.5,1,0
 PointEntitySmooth cube,sphere,1.1,1.1
 MoveEntity cube,0,0,0.09
 RenderWorld
 Flip
Wend

End

; points an entity towards another smoothly
Function PointEntitySmooth( e1,e2,pitch_speed#,yaw_speed# )
 Local yaw#=EntityYaw(e1)
 Local pitch#=EntityPitch(e1)
 PointEntity e1,e2
 Local d_yaw#=EntityYaw(e1)-yaw#
 Local d_pitch#=EntityPitch(e1)-pitch#
 If d_yaw>=180 d_yaw=d_yaw-360 Else If d_yaw<-180 d_yaw=d_yaw+360
 If d_pitch>=180 d_pitch=d_pitch-360 Else If d_pitch<-180 d_pitch=d_pitch+360
 If d_yaw>yaw_speed d_yaw=yaw_speed Else If d_yaw<-yaw_speed d_yaw=-yaw_speed
 If d_pitch>pitch_speed d_pitch=pitch_speed Else If d_pitch<-pitch_speed d_pitch=-pitch_speed
 RotateEntity e1,pitch+d_pitch,yaw+d_yaw,0
End Function