Page 1 of 1

First-person view with collisions in 3d

Posted: Sat Jun 15, 2013 7:11 am
by easy
Hello everyone, I am suffering for a week I can not do the movement with a view from the eye. How is it done? We need to create a node and attach it to the camera and the object? But then physics does not work. Can you tell me how to do it or see my source code and the code has not got to finish what I could find out? I posted the source code to disk Google. thank you :wink:

source - https://docs.google.com/file/d/0B73Vvz7 ... sp=sharing

Re: First-person view with collisions in 3d

Posted: Sat Jun 15, 2013 9:30 am
by Demivec
There is an example in the PureBasic folders, 'Examples\3D\CameraTrack.pb', that might be useful for you to look at. There are some other examples in those folders that might prove useful for you also.

I'm not sure if they address the trouble you have been having with the physics.

Re: First-person view with collisions in 3d

Posted: Sat Jun 15, 2013 10:15 am
by Fred
There is a demo called FPSFirstPerson.pb which show a basic FPS with collisions and physics

Re: First-person view with collisions in 3d

Posted: Sat Jun 15, 2013 10:20 am
by easy
Fred wrote:There is a demo called FPSFirstPerson.pb which show a basic FPS with collisions and physics
I could not make out what's going on there, can you explain or correct code please?

Lot of structure makes it difficult to read the code :(

Re: First-person view with collisions in 3d

Posted: Sat Jun 15, 2013 12:10 pm
by easy
help

Re: First-person view with collisions in 3d

Posted: Sat Jun 15, 2013 3:25 pm
by applePi
Hi easy
before a few months i need to make a room textured with stars, and i need to move inside the room which have a table and a football, and when you enter the room door the football fall down and a music alarm , so i have used the FPSFirstPerson.pb example, but even i don't understand how it works because it is a mathematics and geometry problem (vectors ...etc) , and i want only to focus on my specific roaming inside the room issue, so the following is an example of utilizing a complex example without knowing how it works, the example have physics and you can't go inside the room but only from its door. open the computer speakers
download the files from here
http://www.mediafire.com/?d4c445nj1lzfu85
put all the files in the same folder
PS: i can't download your code, i have used opera and then google chrome and i have signed in but i can't download it
here is the code but it needs the files in the above link
the camera here are inside the eyes of the robot, but if you want the robot to be at specific distance, i need more time to study the original FPSFirstPerson.pb since my program are several months ago

Code: Select all

#PlayerSpeed = 200
#CameraSpeed = 14
Global collision
Global joint = 66
Enumeration
   #tex = 100
   #mat
   #BillboardGroup
   #Billboard
   #table
   #leg1
   #leg2
   #leg3
   #leg4
   #tableMaterial
   #football
   #camera
   #cameraBody ; the robot
         
 EndEnumeration
 Structure Vector3
  x.f
  y.f
  z.f
EndStructure

Structure s_Key
  Up.i
  Down.i
  Left.i
  Right.i
  Jump.i
EndStructure

Structure s_Entity
  EntityBody.i
  BodyOffsetY.f 
  elapsedTime.f
  Fov.f
  Key.s_Key
  MainNode.i  
  CameraNode.i  
  HandNode.i
  ForwardNode.i
  StrafeNode.i
EndStructure


Macro GetNodePosition(Position, Node)
  Position\x = NodeX(Node)  
  Position\y = NodeY(Node)  
  Position\z = NodeZ(Node)  
EndMacro

Macro SubVector3(V, V1, V2)
  V\x = V1\x - V2\x
  V\y = V1\y - V2\y
  V\z = V1\z - V2\z
EndMacro

;-Declare
Declare HandleEntity(*Entity.s_Entity)
 
Define Robot.s_Entity
Define.f KeyX, KeyY, MouseX, MouseY


If InitEngine3D()
ExamineDesktops()

Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  InitSound()
  
DeskWidth=DesktopWidth(0)
DeskHeight=DesktopHeight(0)
    If LoadFont(0, "Arial", 30,#PB_Font_Bold)
      SetGadgetFont(#PB_Default, FontID(0))
    EndIf
    
  OpenWindow(0, 0, 0, DeskWidth, DeskHeight, "Room _ press space to fly, arrows to move, mouse to rotate ", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)

  OpenWindowedScreen(WindowID(0), 0, 0, DeskWidth, DeskHeight, 0, 0, 0)
        
  LoadSound(collision,"britneyspears3.wav")
      
    LoadMesh(0, "room_obj.mesh")
    CreateEntity(0,MeshID(0), #PB_Material_None,0,-35,0)
    RotateEntity(0, 0,-17,0)
    ScaleEntity(0,16000,11000,16000)
    ;ScaleEntity(0,35000,20000,35000)
    EntityPhysicBody(0, #PB_Entity_StaticBody )
        
    CreateSphere(#football, 50)
    CreateMaterial(34, LoadTexture(34, "football.jpg"))
    CreateEntity(#football,MeshID(#football), MaterialID(34),0,1000,0)
    
    EntityPhysicBody(#football, #PB_Entity_SphereBody   , 5,2,3)
    PointJoint(joint, EntityID(#football), 0, 10, 0 ,   EntityID(0), 0, 1000, 0)

    ;plane textured with squares
    CreateMaterial(3, LoadTexture(3, "MRAMOR6X6.jpg"))
    MaterialCullingMode(3, #PB_Material_NoCulling )
    CreatePlane(1,7000,7000,1,1,8,8)
    CreateEntity(1,MeshID(1),MaterialID(3),0,0,0)
    EntityPhysicBody(1, #PB_Entity_StaticBody,1,0.3,1)
       
    ; Camera 
    CreateCamera(#camera, 0, 0, 100, 100)
    CameraBackColor(#camera, RGB(177,191,245))
    ;MoveCamera(0,0, 100, 300,#PB_Absolute)
    ;MoveCamera(#camera,-226.81, 334.93, 3474.49,#PB_Absolute)
    ;MoveCamera(#camera,-226.81, 334.93, 0,#PB_Absolute)
    CameraLookAt(#camera, 0, 0, 0)
        
    ; Light
    CreateLight(0, RGB(230,230,230), 0, 2000, 0) ; general light
    SetLightColor(0, #PB_Light_SpecularColor, RGB(255,255,255))
    CreateLight(1, RGB(230,230,230), 0, 200, 0) ; light in the position of the sprite
    SetLightColor(1, #PB_Light_SpecularColor, RGB(255,255,255))
    
    WorldShadows(#PB_Shadow_Additive , 6000, RGB(200,200,200))
    LoadTexture(#tex , "Lensflare5.jpg") ; for the sprite
    CreateMaterial(#mat, TextureID(#tex))
    SetMaterialColor(#mat, #PB_Material_AmbientColor, RGB(1,1,1))
    SetMaterialColor(#mat, #PB_Material_DiffuseColor, RGB(1,1,1))
    DisableMaterialLighting(#mat, 1)
    MaterialBlendingMode(#mat, #PB_Material_Add )
    MaterialDepthWrite(#mat, Disable)
    CreateBillboardGroup(#BillboardGroup, MaterialID(#mat), 100,100, 0, 0, 0)
    AddBillboard(#Billboard, #BillboardGroup, 0, 200, 0)
    
    ; table and its 4 Legs
    CreateMaterial(#tableMaterial, LoadTexture(#tex , "Wood.jpg"))
    CreateCube(#table, 10)
    CreateEntity(#table,MeshID(#table), MaterialID(#tableMaterial),0,35,0)
    EntityPhysicBody(#table, #PB_Entity_ConvexHullBody  , 100,1,1)
    ScaleEntity(#table,10,1,20)
    CopyEntity(#table, #leg1)
    ScaleEntity(#leg1, 0.3,1,0.05)
    RotateEntity(#leg1, 0,0,90)
    MoveEntity(#leg1, 40, 16,90)
    EntityPhysicBody(#leg1, #PB_Entity_ConvexHullBody  , 4,0,100)
    CopyEntity(#leg1, #leg2)
    RotateEntity(#leg2, 0,0,90)
    MoveEntity(#leg2, -40, 16,90)
    EntityPhysicBody(#leg2, #PB_Entity_ConvexHullBody  , 4,0,100)
    CopyEntity(#leg1, #leg3)
    RotateEntity(#leg3, 0,0,90)
    MoveEntity(#leg3, -40, 16,-90)
    EntityPhysicBody(#leg3, #PB_Entity_ConvexHullBody  , 4,0,100)
    CopyEntity(#leg1, #leg4)
    RotateEntity(#leg4, 0,0,90)
    MoveEntity(#leg4, 40, 16,-90)
    EntityPhysicBody(#leg4, #PB_Entity_ConvexHullBody  , 4,0,100)
        
    ;- Robot Body
    LoadMesh (#cameraBody, "robot.mesh")
    CreateEntity(#cameraBody, MeshID(#cameraBody), #PB_Material_None, -227, 335, 3474)
    EntityPhysicBody(#cameraBody, #PB_Entity_ConvexHullBody , 0.45, 0, 0) ; robot
    With Robot
      \Fov = 50
      \EntityBody = #cameraBody
      \BodyOffsetY = 43 
      \Key\Down  = #PB_Key_Down ;Down
      \Key\Left  = #PB_Key_Left ;Left
      \Key\Right = #PB_Key_Right;Right
      \Key\Up    = #PB_Key_Up   ;Up
      \Key\Jump  = #PB_Key_Space
    
      \MainNode   = CreateNode(#PB_Any) ; Entity position
      \CameraNode = CreateNode(#PB_Any,  0, 140,  50) ; Camera position
      \HandNode   = CreateNode(#PB_Any,  0, 80,  0) ; Hand position
      \ForwardNode= CreateNode(#PB_Any,  0,  0, -1) ; Direction normalized 
      \StrafeNode = CreateNode(#PB_Any, -1,  0,  0) ; Direction normalized
      
      AttachNodeObject(\MainNode  , NodeID(\CameraNode))   
      AttachNodeObject(\MainNode  , NodeID(\HandNode))   
      AttachNodeObject(\MainNode  , NodeID(\ForwardNode))
      AttachNodeObject(\MainNode  , NodeID(\StrafeNode))
            
      ;RotateNode(\HandNode, 5, 0, 0, #PB_Relative)
      
    EndWith
    
    ; Camera
    CreateCamera(#camera, 0, 0, 100, 100)
    CameraBackColor(#camera, RGB(177,191,245))
    CameraRange(#camera, 0.08, 5000) 
    AttachNodeObject(Robot\CameraNode, CameraID(#camera))
    CameraLookAt(#camera, NodeX(Robot\ForwardNode) * 100, NodeY(Robot\CameraNode), NodeZ(Robot\ForwardNode) * 100) 
    ;WorldDebug(#PB_World_DebugBody)
    HideEntity(#cameraBody, 1)
    Repeat
      ;Screen3DEvents()
      If Engine3DFrameRate(#PB_Engine3D_Current)
        Robot\elapsedTime = 40/Engine3DFrameRate(#PB_Engine3D_Current)
        ;Robot\elapsedTime = 40/75
      EndIf  
      
      HandleEntity(@Robot)
      RenderWorld(60)
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    Else
      MessageRequester("Error", "The 3D Engine can't be initialized",0)
      
  EndIf

FreeSound(collision)
End
  

Procedure HandleEntity(*Entity.s_Entity)
  Protected.Vector3 Forward, Strafe, PosMain, PosDir, PosStrafe 
  Protected.f Speed, Speed2, SpeedShoot, x, y
  Protected.f MouseX, MouseY
  Static Jump.f, MemJump.i, Rot.Vector3, Trans.Vector3, Clic
  
  
  With *Entity
    GetNodePosition(PosMain, \MainNode)
    GetNodePosition(PosDir, \ForwardNode)
    GetNodePosition(PosStrafe, \StrafeNode)
    SubVector3(Forward, PosDir, PosMain)
    SubVector3(Strafe, PosStrafe, PosMain)
    
    Speed = #PlayerSpeed * \elapsedTime
    Speed2 = Speed * 0.5
    SpeedShoot = Speed * 10
    
     
    If  ExamineMouse()
      
      MouseX = -(MouseDeltaX()/200) * \Fov * \elapsedTime
      MouseY = -(MouseDeltaY()/200) * \Fov * \elapsedTime
      Rot\z = 0
      Rot\y + MouseX
      If NodePitch(\CameraNode) < 80 And MouseY > 0
        Rot\x + MouseY
      ElseIf NodePitch(\CameraNode) > -80 And MouseY < 0 
        Rot\x + MouseY
      EndIf  
              
      If MouseButton(#PB_MouseButton_Right)
        If \Fov > 20
          \Fov - 2 * \elapsedTime
        EndIf  
      Else
        If \Fov < 50
          \Fov + 2 * \elapsedTime
        EndIf  
      EndIf
      
    EndIf
    If ExamineKeyboard()
      
      If KeyboardPushed(\Key\Jump); And OnGround(*Entity)
        Jump = 30
        MemJump = 1
      EndIf 
      
      Rot\x * 0.30
      Rot\y * 0.30
      Rot\z * 0.30
      Trans\x * 0.80
      Trans\y = Jump
      Trans\z * 0.80
      
      If KeyboardPushed(\Key\Up)
        Trans\x = Forward\x * Speed
        Trans\z = Forward\z * Speed
      ElseIf KeyboardPushed(\Key\Down)
        Trans\x = Forward\x * -Speed2
        Trans\z = Forward\z * -Speed2
      EndIf
      
      If KeyboardPushed(\Key\Left)
        Trans\x = Strafe\x * Speed
        Trans\z = Strafe\z * Speed
      ElseIf KeyboardPushed(\Key\Right)
        Trans\x = Strafe\x * -Speed
        Trans\z = Strafe\z * -Speed
      EndIf 
      
      MoveEntity(\EntityBody, Trans\x, Trans\y, Trans\z)
      re = RayCollide(-406, 0.35, 1603, 324, 0.35, 1555)
      If re > 0
        PlaySound(collision)
        FreeJoint(joint)
        ApplyEntityImpulse(#football,  0, -10, 0,  0,0,0)
        

      EndIf  
      
    EndIf
    If KeyboardReleased(#PB_Key_Z) ; for knowledge of position only and not necessary
        Debug EntityX(\EntityBody)
        Debug EntityY(\EntityBody)
        Debug EntityZ(\EntityBody)
      EndIf
    Jump=-100    
    
    CameraFOV(#camera, \Fov)  
       
    RotateEntity(\EntityBody,     0, Rot\y, 0, #PB_Relative)
    RotateNode(\CameraNode  , Rot\x,     0, 0, #PB_Relative)
    RotateNode(\HandNode    , Rot\x,     0, 0, #PB_Relative)
    
    MoveNode(\MainNode, EntityX(\EntityBody), EntityY(\EntityBody) - \BodyOffsetY, EntityZ(\EntityBody), #PB_Absolute) 
    RotateNode(\MainNode, 0, EntityYaw(\EntityBody), 0) 
    
  EndWith   
EndProcedure

Re: First-person view with collisions in 3d

Posted: Sun Jun 16, 2013 6:48 pm
by Samuel
I took a look at your source code and made a few small changes. I'm not sure if this is the result you were looking for.
Let me know if it's wrong and I'll try again.

EDIT: I'm really sorry if you tried this and it didn't work. I created two different versions of this and I gave you the one that didn't work correctly.
I changed it to the working version. So, it should be OK now.

EDIT2: It seems this one isn't working right either. :oops:
If you let the white cube hit the floor before you move. It will go through the other cubes, but if you move forward while its still falling then
it hits the others properly. I have no clue why this is happening. So, I wouldn't trust my code because I seem to be creating more problems then solving.
Sorry.

Code: Select all

ExamineDesktops()
Global sizeW.i = DesktopWidth(0)
Global sizeH.i = DesktopHeight(0)
Global exit = #False

Global camX.d = 0
Global camY.d = 0

Global playerX.d = 400
Global playerY.d = 50
Global playerZ.d = 500
Global playerSp.d = 2.5

Declare Test()

If InitEngine3D() = 0 Or InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0 Or UsePNGImageDecoder() = 0 Or UseJPEGImageDecoder() = 0
	exit = #True
EndIf

OpenScreen (sizeW, sizeH, 32, "Game3D")
SetFrameRate(60)

Global cCamera.i = CreateCamera (#PB_Any, 0, 0, 100, 100)
MoveCamera(cCamera, 0, playerY, 0, #PB_Absolute)

crMechPlayer.i = CreateCube (#PB_Any, 50)
Global crEntPlayer.i = CreateEntity(#PB_Any, MeshID(crMechPlayer), #PB_Material_None, 0, 200, 0)
EntityPhysicBody(crEntPlayer, #PB_Entity_BoxBody, 5, 0, 0)


EnableWorldPhysics(#True)
EnableWorldCollisions(#True)

AmbientColor(RGB(255, 255, 255))

CreateTexture(0,32,32)
StartDrawing(TextureOutput(0))
Box(0,0,16,16,RGB(255,0,0))
Box(16,16,32,32,RGB(0,120,255))
StopDrawing()
CreateTexture(1,32,32)
StartDrawing(TextureOutput(1))
Box(0,0,16,16,RGB(0,255,0))
Box(16,16,32,32,RGB(0,255,255))
StopDrawing()
CreateTexture(2,32,32)
StartDrawing(TextureOutput(2))
Box(0,0,16,16,RGB(255,0,0))
Box(16,16,32,32,RGB(255,125,0))
StopDrawing()
CreateMaterial(0, TextureID(0))
CreateMaterial(1, TextureID(1))
CreateMaterial(2, TextureID(2))


CreatePlane(0, 12800, 12800, 40, 40, 50, 50)
CreateEntity(0, MeshID(0), MaterialID(0))
EntityPhysicBody(0, #PB_Entity_StaticBody, 0)


CreateCube (1, 50)
CreateEntity(1, MeshID(1), MaterialID(1), 20, 200, 300)
EntityPhysicBody(1, #PB_Entity_BoxBody, 1)

CreateCube (2, 50)
CreateEntity(2, MeshID(2), MaterialID(1), 20, 300, 300)
EntityPhysicBody(2, #PB_Entity_BoxBody, 1)

CreateCube (3, 50)
CreateEntity(3, MeshID(3), MaterialID(2), 20, 30, 500)
EntityPhysicBody(3, #PB_Entity_BoxBody)

Repeat
	ExamineKeyboard()
        Test()
	
	FlipBuffers()
	RenderWorld(60)
Until exit = #True
End



Procedure Test()
	If KeyboardPushed (#PB_Key_W)
		playerZ + Cos(Radian(CameraYaw(cCamera) + 180)) * playerSp
		playerX + Sin(Radian(CameraYaw(cCamera) + 180)) * playerSp
		
		MoveEntity(crEntPlayer, EntityX(crEntPlayer), EntityY(crEntPlayer), EntityZ(crEntPlayer) + 5, #PB_Absolute)
	EndIf

	If KeyboardPushed (#PB_Key_S)
		playerZ - Cos(Radian(CameraYaw(cCamera) + 180)) * playerSp
		playerX - Sin(Radian(CameraYaw(cCamera) + 180)) * playerSp
	EndIf
	
	If KeyboardPushed (#PB_Key_A)
		playerZ + Cos(Radian(CameraYaw(cCamera) - 90)) * playerSp
		playerX + Sin(Radian(CameraYaw(cCamera) - 90)) * playerSp
	EndIf
	
	If KeyboardPushed (#PB_Key_D)
		playerZ + Cos(Radian(CameraYaw(cCamera) + 90)) * playerSp
		playerX + Sin(Radian(CameraYaw(cCamera) + 90)) * playerSp
	EndIf
	
	If KeyboardPushed (#PB_Key_Space)
		playerY + 10
	EndIf
	
	If KeyboardPushed (#PB_Key_LeftShift)
		playerSp = 5
	Else
		playerSp = 2.5
	EndIf
	
	If KeyboardPushed (#PB_Key_Escape)
		exit = #True
	EndIf
	
	If ExamineMouse()
		camX = -MouseDeltaX() * 1 * 0.05
		camY = -MouseDeltaY() * 1 * 0.05
	EndIf	
	
	MoveCamera(cCamera, EntityX(crEntPlayer), EntityY(crEntPlayer) + 150, EntityZ(crEntPlayer) - 300, #PB_Absolute)
	CameraLookAt(cCamera, EntityX(crEntPlayer), EntityY(crEntPlayer), EntityZ(crEntPlayer))
	RotateCamera(cCamera, camY, 0, 0, #PB_Relative)
EndProcedure


Re: First-person view with collisions in 3d

Posted: Sun Jun 23, 2013 4:19 pm
by Comtois
i modified your code.
Read this, your mesh are too big.

Code: Select all

ExamineDesktops()
Global sizeW.i = DesktopWidth(0)
Global sizeH.i = DesktopHeight(0)
Global exit = #False

Global camX.d = 0
Global camY.d = 0

Global playerX.d = 400
Global playerY.d = 50
Global playerZ.d = 500
Global playerSp.d = 2.5

Declare Test()
Declare CameraFollow()


If InitEngine3D(0) = 0 Or InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0 ;Or UsePNGImageDecoder() = 0 Or UseJPEGImageDecoder() = 0
  exit = #True
EndIf
OpenScreen (sizeW, sizeH, 32, "Game3D")
SetFrameRate(60)


Global cCamera.i = CreateCamera (#PB_Any, 0, 0, 100, 100)
MoveCamera(cCamera, 0, playerY, 0, #PB_Absolute)

crMechPlayer.i = CreateCube (#PB_Any, 1)
Global crEntPlayer.i = CreateEntity(#PB_Any, MeshID(crMechPlayer), #PB_Material_None, 0, 20, 0)
EntityPhysicBody(crEntPlayer, #PB_Entity_BoxBody, 1, 0, 0)


EnableWorldPhysics(#True)
EnableWorldCollisions(#True)

AmbientColor(RGB(255, 255, 255))

CreateTexture(0,32,32)
StartDrawing(TextureOutput(0))
Box(0,0,16,16,RGB(255,0,0))
Box(16,16,32,32,RGB(0,120,255))
StopDrawing()
CreateTexture(1,32,32)
StartDrawing(TextureOutput(1))
Box(0,0,16,16,RGB(0,255,0))
Box(16,16,32,32,RGB(0,255,255))
StopDrawing()
CreateTexture(2,32,32)
StartDrawing(TextureOutput(2))
Box(0,0,16,16,RGB(255,0,0))
Box(16,16,32,32,RGB(255,125,0))
StopDrawing()
CreateMaterial(0, TextureID(0))
CreateMaterial(1, TextureID(1))
CreateMaterial(2, TextureID(2))


CreatePlane(0, 128, 128, 40, 40, 50, 50)
CreateEntity(0, MeshID(0), MaterialID(0))
EntityPhysicBody(0, #PB_Entity_StaticBody, 0)


CreateCube (1, 1)
CreateEntity(1, MeshID(1), MaterialID(1), 20, 20, 30)
EntityPhysicBody(1, #PB_Entity_BoxBody, 1)

CreateCube (2, 1)
CreateEntity(2, MeshID(2), MaterialID(1), 20, 30, 30)
EntityPhysicBody(2, #PB_Entity_BoxBody, 1)

CreateCube (3, 1)
CreateEntity(3, MeshID(3), MaterialID(2), 20, 30, 500)
EntityPhysicBody(3, #PB_Entity_StaticBody)
WorldDebug(#PB_World_DebugBody)
Repeat
  If ExamineKeyboard()
    Test()
  EndIf
  CameraFollow()   
  FlipBuffers()
  RenderWorld(60)
Until exit = #True
End



Procedure Test()
  playerSp = 0
  If KeyboardPushed (#PB_Key_Up)
    playerSp = 5
  ElseIf KeyboardPushed (#PB_Key_Down)
    playerSp = -5
  EndIf
  
  If KeyboardPushed (#PB_Key_Left)
    RotateEntity(crEntPlayer, 0, 1, 0, #PB_Relative)
  ElseIf KeyboardPushed (#PB_Key_Right)
    RotateEntity(crEntPlayer, 0, -1, 0, #PB_Relative)
  EndIf
  
  If KeyboardPushed (#PB_Key_Space)
    playerY + 10
  EndIf
  
  
  
  If KeyboardPushed (#PB_Key_Escape)
    exit = #True
  EndIf
  
  If ExamineMouse()
    camX = -MouseDeltaX() * 1 * 0.05
    camY = -MouseDeltaY() * 1 * 0.05
  EndIf   
  MoveEntity(crEntPlayer, 0, -9, playerSp, #PB_Local)
EndProcedure

Procedure CameraFollow()
  Distance = 10
  Angle.f = EntityYaw(crEntPlayer)-180
  x.f = EntityX(crEntPlayer)+Sin(Radian(Angle))*Distance
  z.f = EntityZ(crEntPlayer)+Cos(Radian(Angle))*Distance
  MoveCamera(cCamera, x, EntityY(crEntPlayer) + 5, z, #PB_Absolute)
  
  CameraLookAt(cCamera, EntityX(crEntPlayer), EntityY(crEntPlayer), EntityZ(crEntPlayer))
EndProcedure

Re: First-person view with collisions in 3d

Posted: Sun Jun 23, 2013 6:49 pm
by Samuel
Thank you for the link, Comtois! Your code runs perfect. No problems at all.
I'll have to make sure all of my meshes, that use physics, are within the proper scale.