Ooops
November 25, 2020, 08:36:58 AM

Author Topic: [bb] 3rd-Person Camera by Mattizzle [ 1+ years ago ]  (Read 557 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] 3rd-Person Camera by Mattizzle [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : 3rd-Person Camera
Author : Mattizzle
Posted : 1+ years ago

Description : Stuff. Here is a basic 3rd-person camera. There is no collision detecting and no camera local z movement (no zoom in/out). But both of those things should be easily implemented. I'm working on that too.

Also, IDEal is used. So when you see a ";[Block]", that is for collapsing in the IDE.


Code :
Code: BlitzBasic
  1. Function CurveValue#(newvalue#,oldvalue#,increments )
  2.         If increments>1 oldvalue#=oldvalue#-(oldvalue#-newvalue#)/increments
  3.         If increments<=1 oldvalue=newvalue
  4.         Return oldvalue#
  5. End Function
  6.  
  7. DebugLog "Initiating..."
  8.  
  9. ;[Block] Graphics
  10. Graphics3D 800,600,0,2
  11. SetBuffer BackBuffer()
  12. HidePointer()
  13.  
  14. DebugLog "Graphics Set"
  15. ;[End Block]
  16.  
  17. ;[Block] Light
  18. Global light=CreateLight()
  19. RotateEntity light,25,0,0
  20. AmbientLight 110,110,110
  21.  
  22. DebugLog "Lights Created"
  23. ;[End Block]
  24.  
  25. ;[Block] Create Player
  26. Global player, pz, px
  27. player = CreateCube()
  28.  
  29. RotateEntity player, 0,180,0
  30.  
  31. tex = CreateTexture(16,16)
  32. SetBuffer TextureBuffer(tex)
  33. ClsColor 255,255,255
  34. Cls
  35. font = LoadFont("ariel",24)
  36. SetFont font
  37. Color 255,0,0
  38. Text 4,0,"^"
  39.  
  40. EntityTexture player,tex
  41. SetBuffer BackBuffer()
  42.  
  43. DebugLog "Player Created"
  44. ;[End Block]
  45.  
  46. ;[Block] Camera
  47. Global camPivot = CreatePivot()
  48. PositionEntity camPivot, EntityX(player),EntityY(player),EntityZ(player)
  49. RotateEntity camPivot, 0,180,0
  50.  
  51. Global cam = CreateCamera()
  52. CameraRange cam,1,100000
  53. CameraZoom cam,1.4
  54. PositionEntity cam, EntityX(player),EntityY(player)+5,EntityZ(player)-20
  55. EntityParent cam,camPivot
  56.  
  57. Global mousespeedx# = 0.4
  58. Global mousespeedy# = 0.2
  59. Global playerspeed# = 0.8
  60. Global camerasmoothness# = 3
  61. Global mx#, my#, pitch#, yaw#, roll#
  62.  
  63. DebugLog "Camera Has Loaded"
  64. ;[End Block]
  65.  
  66. ;[Block] Random Cubes
  67. For a=1 To 50
  68.         cube = CreateCube()
  69.         PositionEntity cube, Rnd(200)-100,Rnd(200)-100,Rnd(200)-100
  70.         RotateEntity cube, Rnd(360),Rnd(360),Rnd(360)
  71.         ScaleEntity cube, Rnd(5)+0.5,Rnd(5)+0.5,Rnd(5)+0.5
  72.         EntityColor cube, Rnd(255),Rnd(255),Rnd(255)
  73. Next   
  74. ;[End Block]
  75.  
  76.  
  77.  
  78. DebugLog "MainLoop Initiated"
  79. ;[Block] MAIN LOOP
  80. While Not KeyHit(1)
  81.        
  82.         ;[Block] Camera Controls
  83.         mx#=CurveValue(MouseXSpeed()*mousespeedx,mx,camerasmoothness)
  84.         my#=CurveValue(MouseYSpeed()*mousespeedy,my,camerasmoothness)
  85.         MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
  86.         pitch#=EntityPitch(camPivot)
  87.         yaw#=EntityYaw(camPivot)
  88.         pitch=pitch+my
  89.         yaw=yaw-mx
  90.         If pitch > 9  pitch = 9
  91.         If pitch < -49 pitch = -49
  92.  
  93.         RotateEntity camPivot, 0,yaw,0
  94.         TurnEntity camPivot, pitch,0,0
  95.         ;[End Block]
  96.        
  97.        
  98.         ;[Block] Player Controls
  99.         px=(KeyDown(32)-KeyDown(30))
  100.         pz=(KeyDown(17)-KeyDown(31))
  101.  
  102.         If pz = 1 And px = 0 RotateEntity(player, 0,EntityYaw(camPivot)+180,0)
  103.         If pz =-1 And px = 0 RotateEntity(player, 0,EntityYaw(camPivot),0)
  104.         If px = 1 And pz = 0 RotateEntity(player, 0,EntityYaw(camPivot)+90,0)
  105.         If px =-1 And pz = 0 RotateEntity(player, 0,EntityYaw(camPivot)-90,0)
  106.                
  107.         If pz = 1 And px = 1 RotateEntity(player, 0,EntityYaw(camPivot)+135,0)
  108.         If pz = 1 And px =-1 RotateEntity(player, 0,EntityYaw(camPivot)-135,0)
  109.         If pz =-1 And px = 1 RotateEntity(player, 0,EntityYaw(camPivot)+45,0)
  110.         If pz =-1 And px =-1 RotateEntity(player, 0,EntityYaw(camPivot)-45,0)
  111.  
  112.         If pz <> 0 Or px <> 0
  113.                 MoveEntity player, 0,0,playerspeed
  114.         EndIf
  115.         ;[End Block]
  116.        
  117.         PositionEntity camPivot,EntityX(player),EntityY(player),EntityZ(player)
  118.  
  119.         RenderWorld()
  120.         Flip
  121. Wend
  122. ;[End Block]
  123.  
  124. ClearWorld()
  125.  
  126. DebugLog "Memory Freed. Exititing..."
  127.  
  128.  
  129.  
  130. End


Comments :


Link(Posted 1+ years ago)

 Thanks for the code :D


Guy Fawkes(Posted 1+ years ago)

 Yea man, this pawns!


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal