TurnToEntity

Blitz3D Forums/Blitz3D Programming/TurnToEntity

Billamu(Posted 2004) [#1]
Is there a function that works like PointEntity but behaves like TurnEntity so it doesn't snap in the direction of the entity


Matty(Posted 2004) [#2]
I think Align to Vector can do this.


Rob(Posted 2004) [#3]
use turnentity or rotateentity in conjunction with deltapitch and deltayaw


EOF(Posted 2004) [#4]
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



Stevie G(Posted 2004) [#5]
As Rob says just use undocumented DeltaYaw and DeltaPitch - much cleaner. I may have mixed my signs up here.


Function PointEnitity (entity1, entity2, speed# )

 pitch# = -deltapitch(entity1,entity2)
 yaw# = -deltayaw (entity1,entity2)
 turnentity entity1 , pitch * speed , yaw * speed#,0

end function




BlitzSupport(Posted 2004) [#6]
That works very nicely, Stevie, but it seems that the other version (by BitmaniaK if memory serves) works better if you need to switch from turning from one entity to another. If not, that's obviously better!


Stevie G(Posted 2004) [#7]
Does this work better. You can use this to point to anything including a specific point in the world. It will turn at a maximum of 'speed' degrees.

global pivot = createpivot()

Function Point_Entity( entity,speed# , x# , y# , z# )
  positionentity pivot,x,y,z
  pitch# = qlimit( -deltapitch(entity,pivot), -speed,speed)
  yaw# = qlimit ( -deltayaw (entity,pivot), -speed,speed)
  turnentity entity , pitch , yaw ,0
end function

function qlimit#(q#,lo#,hi#)
  if q > hi q = hi
  if q < lo q = lo
return q