turn to face
Blitz3D Forums/Blitz3D Beginners Area/turn to face
| ||
is there a good way to get multiple units to face the same direction? not instantaneous but slowly turn to face one uniform direction? |
| ||
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 |
| ||
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. |
| ||
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 |
| ||
..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 |
| ||
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? |
| ||
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... |
| ||
but deltayaw is like point entity it figures out the needed yaw to make the src_entity point at the dest_entity |
| ||
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 |
| ||
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. |
| ||
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. |
| ||
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. |
| ||
There's no such thing as deltaroll. Oh well, I'm half drunk and I don't use BB3D any more. |
| ||
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 |
| ||
@ 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. |
| ||
true, I'm working on that right now, it does look good for wind though |
| ||
Video? |
| ||
Huh? I'm a little bit confused. I'm using this for smoke and clouds in a game |
| ||
Can you show a video of it? |
| ||
Ah I see I misunderstood you, yes I can get a vid but I don't have a site to post it on |
| ||
use file front |
| ||
Use Bliptv or youtube. |