turn to face

Blitz3D Forums/Blitz3D Beginners Area/turn to face

Ben(t)(Posted 2008) [#1]
is there a good way to get multiple units to face the same direction? not instantaneous but slowly turn to face one uniform direction?


GIB3D(Posted 2008) [#2]
TurnEntity entity,0,DeltaYaw(entity1,entity2)*.5,0

EDIT: You could use that to make them all point at a certain entity like a pivot


Ben(t)(Posted 2008) [#3]
okay two things
1. TurnEntity entity,0,DeltaYaw(entity1,entity2)*.5,0
doesn't work, use the exapmle and put in that line of code the cone just spins

2. I didnt make my self clear apparently

say for instance i have one unit in the lead of ten units behind him, what
i want is that when he turns to face in a direction, the other units follow suit and match his current yaw and pitch so that they are all facing the same direction.


Naughty Alien(Posted 2008) [#4]
Function Turn_Entity(entity,target,smoothness=10)


entang#=DeltaYaw#(entity,target)

If Abs(entang#)>smoothness=10
TurnEntity entity,0,smoothness*Sgn(entang#),0
Else
PointEntity entity,target
EndIf

End Function


Naughty Alien(Posted 2008) [#5]
..or try this..working very nice..

Function EntityPoint( Source , Target, MaxYawSpeed# , MaxPitchSpeed# )

DY# = DeltaYaw( Source, Target )
If Abs( DY ) > MaxYawSpeed DY# = Sgn( DY ) * MaxYawSpeed

DP# = DeltaPitch( Source, Target )
If Abs( DP ) > MaxPitchSpeed DP = Sgn( DP ) * MaxPitchSpeed

TurnEntity Source, 0 , DY , 0;facing but turning only around Y axis
;TurnEntity Source, DP , DY , 0; facing

End Function


Ben(t)(Posted 2008) [#6]
this is not what im looking for, i need a way to make any entity i choose in the function to align to the same pitch and yaw as another entity of my choice.
think of arrows
they are all pointing whereever
but i want them all in one uniformed direction, how would i do that?


Naughty Alien(Posted 2008) [#7]
so they will all be in parallel direction? I may took it wrong but if that is the case, why not modify given function and apply same parameters on to target1,Target2...


Ben(t)(Posted 2008) [#8]
but deltayaw is like point entity it figures out the needed yaw to make the src_entity point at the dest_entity


Stevie G(Posted 2008) [#9]
Graphics3D 1024,768,32,1

light = CreateLight()
camera = CreateCamera()
PositionEntity camera, 0,0,-10

global pivot = createpivot()

Dim cone(5)

cone(0) = CreateCone()
PositionEntity cone(0), 0,5,0
EntityColor cone(0), 255,0,0

For l = 1 To 5
	cone(l) = CreateCone()
	PositionEntity cone(l), (l-3)*3,0,0
Next

While Not KeyDown(1)

	If KeyHit(57)
		RotateEntity cone(0), Rand(-90,90), Rand(-180,180 ), 0
	EndIf


	For l = 1 To 5
		MATCHorientation( cone(l) , cone(0) , .1 )
	Next

	RenderWorld()
	
	For l = 0 To 5
		y = l * 50
		Text 0,y,"Cone "+Str$(l)
		Text 0,y+10,EntityPitch( cone(l) )
		Text 0,y+20,EntityYaw( cone(l) )
		Text 0,y+30,EntityRoll( cone(l) )
	Next

	
	Flip 
	
Wend

Function MATCHorientation( Source , Target , Speed# )

	TFormVector 0,0,10, Target, 0
	
	PositionEntity Pivot , EntityX( Source ) + TFormedX(), EntityY( Source ) + TFormedY() , EntityZ( Source ) + TFormedZ()

	DP# = DeltaPitch( Source , Pivot ) * Speed
	DY# = DeltaYaw( Source , Pivot ) * Speed
	
	TurnEntity Source , DP , DY, 0
	
End Function



Nate the Great(Posted 2008) [#10]
There is a whole science about what you are asking about and it is called emergence. For example when schools of fish stay together and all seem to do the same thing. I haven't tried to make a game based on emergence but I know it has been done.


GfK(Posted 2008) [#11]
RotateEntity Entity1,EntityPitch(Entity2),EntityYaw(Entity12,EntityRoll(Entity2)


You can use DeltaPitch/yaw/roll with a float multiplier between 0 and 1 if you want it to turn gradually.


Stevie G(Posted 2008) [#12]

There is a whole science about what you are asking about and it is called emergence.



It's actually called flocking behaviour.


You can use DeltaPitch/yaw/roll with a float multiplier between 0 and 1 if you want it to turn gradually.



There's no such thing as deltaroll. Even then, this would not work as I understand that he wants to match the orientation of the leading entity rather than point towards it.

I've updated the code I posted above with a simpler version which does what you want.


GfK(Posted 2008) [#13]
There's no such thing as deltaroll.
Oh well, I'm half drunk and I don't use BB3D any more.


Ben(t)(Posted 2008) [#14]
I was using the flocking behavior to have wind patterns in the engine i am building, i have designed a simple function to do this.

Function yawrate(src_entity,dest_entity,turn_rate#)

If EntityYaw#(src_entity)>EntityYaw#(dest_entity) Then
TurnEntity src_entity,0,-turn_rate#,0
EndIf

If EntityYaw#(src_entity)<EntityYaw#(dest_entity) Then
TurnEntity src_entity,0,turn_rate#,0
EndIf

End Function

it could be used for anything really


Stevie G(Posted 2008) [#15]
@ Ben(t),

I thought you also wanted to match pitch? If you don't then that's fine as you won't run into any gimbal lock related singularities.

I should point out that your code will not work correctly in certain situations as you do not take into consideration that yaw angles are between -180 and 180, rather than 0 and 360.

For example :

Source_Entity yaw = 45
Dest_Entity yaw = -160

As Source yaw > Dest_Yaw you would be taking the long route which covers 205 degrees rather than the shortest route which covers 155 degrees.


Ben(t)(Posted 2008) [#16]
true, I'm working on that right now, it does look good for wind though


Stevie G(Posted 2008) [#17]
Video?


Ben(t)(Posted 2008) [#18]
Huh? I'm a little bit confused.
I'm using this for smoke and clouds in a game


Stevie G(Posted 2008) [#19]
Can you show a video of it?


Ben(t)(Posted 2008) [#20]
Ah I see I misunderstood you, yes I can get a vid but I don't have a site to post it on


Nate the Great(Posted 2008) [#21]
use file front


Stevie G(Posted 2008) [#22]
Use Bliptv or youtube.