Smooth rotation (turning) of entity
Blitz3D Forums/Blitz3D Beginners Area/Smooth rotation (turning) of entity
| ||
Hi. Let's say i have a simple 3d app with cone that is moving just forward along a path on the plane and it soon knows that wall or any obstacle is directly in front of him that he must avoid by just turning away from it. How to make any mesh or entity rotate smoothly instead of turning instantly by some angle?? This looks ugly. Detecting obstacles and stuff is not difficult. But what i need is smooth turning around or smooth rotation to any other angle (away from wall in this example). It must slowly rotate / turn away. That's what i need. Is there any blitz command that helps me doing that? TIA |
| ||
If you have a precise point where to go, maybe a combination of DeltaYaw + TurnEntity or a combination of DeltaYaw + RotateEntity See : Graphics3D(800,600,32,2) SetBuffer(BackBuffer()) HidePointer() SeedRnd(MilliSecs()) Camera = CreateCamera() CameraRange(Camera,0.1,100) PositionEntity(Camera,0,10,0) RotateEntity(Camera,90,0,0) NpcsMaxCount% = 2 Global NpcsCount% = 0 Dim NpcFeet(NpcsMaxCount) Dim NpcMesh(NpcsMaxCount) For i% = 1 To 2 NpcsCount = NpcsCount + 1 NId% = NpcsCount NpcFeet(NId) = CreatePivot() PositionEntity(NpcFeet(NId),0,0,0) R% = Rand(000,255) G% = Rand(000,255) B% = Rand(000,255) NpcMesh(NId) = CreateCube() ScaleMesh(NpcMesh(NId),0.5/2,1.7/2,0.25/2) PositionMesh(NpcMesh(NId),0,1.7/2,0) EntityColor(NpcMesh(NId),R,G,B) PositionEntity(NpcMesh(NId),EntityX(NpcFeet(NId)),EntityY(NpcFeet(NId)),EntityZ(NpcFeet(NId))) EntityParent(NpcMesh(NId),NpcFeet(NId),True) NpcZAxis = CreateCube() ScaleMesh(NpcZAxis,0.1/2,0.1/2,1.0/2) EntityColor(NpcZAxis,R,G,B) PositionEntity(NpcZAxis,0,0+0.85,1.0/2) EntityParent(NpcZAxis,NpcFeet(NId),True) Next VectorNpc1Npc2 = CreateCube() ScaleMesh(VectorNpc1Npc2,0.1/2,0.1/2,1.0/2) PositionMesh(VectorNpc1Npc2,0,0,1.0/2) PositionEntity(VectorNpc1Npc2,EntityX(NpcMesh(1),True),EntityY(NpcMesh(1),True),EntityZ(NpcMesh(1),True)) EntityParent(VectorNpc1Npc2,NpcMesh(1),True) PositionEntity(NpcFeet(1),0,0,-3.0) DLight = CreateLight(1) LightColor(DLight,255,255,255) PositionEntity(DLight,0,1024,-1024) RotateEntity(DLight,45,0,0) AmbientLight(125,125,125) Repeat Cls() If(KeyDown(17)>0) MoveEntity(NpcFeet(1),0,0,0.1) EndIf If(KeyDown(30)>0) MoveEntity(NpcFeet(1),-0.1,0,0) EndIf If(KeyDown(31)>0) MoveEntity(NpcFeet(1),0,0,-0.1) EndIf If(KeyDown(32)>0) MoveEntity(NpcFeet(1),0.1,0,0) EndIf VLength# = EntityDistance(NpcFeet(1),NpcFeet(2)) ScaleEntity(VectorNpc1Npc2,1.0,1.0,VLength) PointEntity(VectorNpc1Npc2,NpcFeet(2)) CurDeltaYaw# = DeltaYaw(NpcFeet(1),NpcFeet(2)) If(KeyDown(57)>0) If(CurDeltaYaw => 0) TurnEntity(NpcFeet(1),0,1,0) ElseIf(CurDeltaYaw < 0) TurnEntity(NpcFeet(1),0,-1,0) EndIf EndIf RenderWorld() Text(0,0,"CurDeltaYaw = "+CurDeltaYaw) Flip(True) Until(KeyDown(1)>0) End Press the space key to see the smooth turn. |
| ||
Thank you very much. Exactly what i need. Didn't know about DeltaYaw. Very useful thing. |