Dota, Mobile Legends or MOBA Style Camera and Controls
Attention! 👉Starting November 2024, BlitzCoder.org will now be BlitzBasic.org.
Tweet blitz3d code-archives miscellaneous
Basic camera point of view and point and click control for Dota, WarCraft, Mobile Legends, MOBA game style with terrain support (not flat).
Assets used can be found in the same folder as samples/mak/xfighter
Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()
terr = LoadTerrain("hmap_1024.bmp")
ScaleEntity terr, 15, 450, 15
PositionEntity terr, -20*512, 0, -20*512
EntityPickMode terr, 2
tex1 = LoadTexture("coolgrass2.bmp", 1)
ScaleTexture tex1, 10, 10
tex2 = LoadTexture("lmap_256.bmp")
ScaleTexture tex2, TerrainSize(terr), TerrainSize(terr)
EntityTexture terr, tex1, 0, 0
EntityTexture terr, tex2, 0, 1
Global cam = CreateCamera()
PositionEntity cam, 500, 1500, -500,True
center = CreatePivot()
PointEntity cam, center
CameraRange cam, 10.0, 5000.0
l = CreateLight()
MoveEntity l,-50,50,50
PointEntity l,center
Global Char = CreateSphere()
ScaleEntity Char, 25, 25, 25 ; ---------- Radius of the sphere is "25" units.
EntityColor Char, 255, 0, 0
PositionEntity Char, 0.0, 1000.0, 0.0
TranslateEntity Char, 0.0, -1000.0, 0.0
Const CharSpeed# = 0.5
Local tempY#
MoveMouse GraphicsWidth() / 2, GraphicsHeight() / 2
mousespeed# = 0.5
camerasmoothness# = 4.5
Global target
While Not KeyHit(1)
LMBHit = MouseHit(1)
mxs# = CurveValue(MouseXSpeed() * mousespeed, mxs, camerasmoothness)
mys# = CurveValue(MouseYSpeed() * mousespeed, mys, camerasmoothness)
camxa# = camxa - mxs Mod 360
camya# = camya + mys
If camya < -89 Then camya = -89
If camya > 89 Then camya = 89
MoveMouse GraphicsWidth() / 2, GraphicsHeight() / 2
RotateEntity cam, camya, camxa, 0.0
If LMBHit > 0 Then
PickedMesh = CameraPick(cam, MouseX(), MouseY())
If PickedMesh Then
If target <> 0 Then FreeEntity target
target = CreateSphere()
ScaleEntity target, 25, 25, 25
PositionEntity target, PickedX(), PickedY(), PickedZ()
EndIf
EndIf
If target <> 0 Then
If EntityDistance(Char, target) > 30.0 Then
TurnEntity Char,0,DeltaYaw(Char,Target),0
TFormPoint 0,0,CharSpeed, Char, 0
tempY = TerrainY(terr,TFormedX(),TFormedY(),TFormedZ())
PositionEntity Char,TFormedX(),(tempY+25),TFormedZ()
Else
PositionEntity Char,EntityX(Target,True),EntityY(Target,True)+25,EntityZ(target,True),True
FreeEntity target
target = 0
EndIf
EndIf
UpdateWorld
RenderWorld
Flip
Wend
End
Function CurveValue#(newvalue#, oldvalue#, increments)
If increments > 1 Then oldvalue# = oldvalue# - (oldvalue# - newvalue#) / increments
If increments <= 1 Then oldvalue# = newvalue#
Return oldvalue#
End Function
Reply To Topic (minimum 10 characters)
Please log in to reply