Smooth rotation (turning) of entity


Tweet blitz3d code-archives miscellaneous tutorials
(Posted 2 months ago) RemiD

Face another entity using combination of DeltaYaw + TurnEntity or a combination of DeltaYaw + RotateEntity

Use WASD to move, SPACE to face towards the other entity.

Image

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

Reply To Topic (minimum 10 characters)

Please log in to reply