Move camera while holding down right click third person


👉Blast3D is now FREE👈

Support Future Updates by Becoming a Blitz Backer on Patreon.

 

Tweet
john

How to move camera while holding down right click third person

Hrobo88 commented:
;-------Creating the camera-------
entity=CreateCube() ;Create the entity, can be anything, you can even load in a mesh/model

pivot=CreatePivot(entity) ;Parent the pivot to the entity

camera=CreateCamera(pivot) ;Parent the camera to the pivot
PositionEntity camera,0,0,-5 ;Move the camera away from the entity, the further back the bigger the radius

turning=False

;-------Main Loop -------

PointEntity camera,entity ;Have the camera always look at the entity

If Not MouseDown(2) Then turning=False ;If there is no right click detected, put turning to false

If MouseDown(2) And turning=False Then ;Fixiate the mouse
    mx#=MouseX()
    my#=MouseY()
    turning=True
    MouseXSpeed
    MouseYSpeed ;Measure the MouseX & MouseY speed otherwise it will 'snap' the camera
EndIf

If turning=True Then 
    camyaw#=camyaw#-MouseXSpeed()
    campitch#=campitch#+MouseYSpeed()
    If campitch#>89.9 Then campitch#=89.9 ;Limit the camera rotation so it doesnt go upside down
    If campitch#<-89.9 Then campitch#=-89.9  
    RotateEntity pivot,campitch#,camyaw#,0 ;Regular mouselook
    MoveMouse mx#,my#
EndIf

If you need an example scenery (just a simple hello cube)

Graphics3D 800,600,0,2

entity=CreateCube() ;Create the entity, can be anything, you can even load in a mesh/model

pivot=CreatePivot(entity) ;Parent the pivot to the entity

camera=CreateCamera(pivot) ;Parent the camera to the pivot
PositionEntity camera,0,0,-5 ;Move the camera away from the entity, the further back the bigger the radius

light=CreateLight(2)
PositionEntity light,0,0,-10 ;Make the scenery  :P

turning=False

While Not KeyDown(1) ;Main Loop

PointEntity camera,entity ;Have the camera always look at the entity

If Not MouseDown(2) Then turning=False ;If there is no right click detected, put turning to false

If MouseDown(2) And turning=False Then ;Fixiate the mouse
    mx#=MouseX()
    my#=MouseY()
    turning=True
    MouseXSpeed
    MouseYSpeed ;Measure the MouseX & MouseY speed otherwise it will 'snap' the camera
EndIf

If turning=True Then 
    camyaw#=camyaw#-MouseXSpeed()
    campitch#=campitch#+MouseYSpeed()
    If campitch#>89.9 Then campitch#=89.9 ;Limit the camera rotation so it doesnt go upside down
    If campitch#<-89.9 Then campitch#=-89.9  
    RotateEntity pivot,campitch#,camyaw#,0 ;Regular mouselook
    MoveMouse mx#,my#
EndIf

RenderWorld() 
UpdateWorld()
Flip
Wend
End
RemiD commented:
if( mousedown(1)=1 ) 
 moveentity( camera, 0, 0, +0.1 ) ; x, y, z
endif

-x is left, +x is right, -y is down, +y is up, -z is backward, +z is forward

Reply To Topic (minimum 10 characters)

Please log in to reply