Hello. I am new here as some of you may already know & I just started a few months ago in DarkBasic Pro. I must say, DarkBasic Pro really has come a long way. It's great to see it's still very popular!
Anyway, I have been working on orbit camera with "invisibility drag", meaning that when the camera rotates past X rotation = 0.0 then the object's negative zoom level becomes the object's positive transparency level. The more you rotate down with the mouse on the Y axis & drag, the more invisible the player becomes when the camera gets closer. This only happens up to a certain point of course.
Here is what I have:
AUTOCAM OFF
SYNC ON : SYNC RATE 60
set camera range 0.01, 10000.0
global zoomlevel#
`Objects Vars
Object = 1
Object2 = 2
Radius = 100
Radius2 = 1000
`Starting Object To Orbit
Orbiting = 1
`Make The Objects To Be Orbited
MAKE OBJECT SPHERE Object,Radius
POSITION OBJECT Object,0,0,0
MAKE OBJECT CUBE Object2,Radius2
POSITION OBJECT Object2,200,0,0
`Position The Camera Somewhere
POSITION CAMERA 0,0,-50
`Initialize the Focuse To Start Distance, Minimum Distance, and Maximum Distance
SetFocusToOrbit(-100,-Radius,-Radius * 5)
`Mainn Loop
DO
`Switch Between Objects
IF KEYSTATE(2)
Orbiting = 1
SetFocusToOrbit(-100,-Radius,-Radius * 5)
ENDIF
IF KEYSTATE(3)
Orbiting = 2
SetFocusToOrbit(-300,-Radius2,-Radius2 * 5)
ENDIF
`Update The Camera Position around the object
UpdateFocusToOrbit(Orbiting)
center text screen width()/2, screen height()/2, "zoomlevel#: "+str$(zoomlevel#)
center text screen width()/2, screen height()/2+20, "Visible: "+str$(object visible(Object))
SYNC
LOOP
/// FUNCTIONS ///
FUNCTION SetFocusToOrbit( StartDis AS FLOAT , MinDis AS FLOAT , MaxDis AS FLOAT )
GLOBAL FocusDistance AS FLOAT
GLOBAL FocusMinDistance AS FLOAT
GLOBAL FocusMaxDistance AS FLOAT
FocusDistance = StartDis
FocusMinDistance = MinDis
FocusMaxDistance = MaxDis
ENDFUNCTION
FUNCTION UpdateFocusToOrbit( Object AS INTEGER )
POSITION CAMERA OBJECT POSITION X(Object),OBJECT POSITION Y(Object),OBJECT POSITION Z(Object)
IF MOUSECLICK()=1
XROTATE CAMERA CAMERA ANGLE X()+MOUSEMOVEY()*0.1
YROTATE CAMERA CAMERA ANGLE Y()+MOUSEMOVEX()*0.1
IF CAMERA ANGLE X()>80 THEN XROTATE CAMERA 80
IF CAMERA ANGLE X()<-30 THEN XROTATE CAMERA -30
if object visible(Object)
zoomlevel# = fade_player_when_zoomed_in(Object, CAMERA ANGLE X()+MOUSEMOVEY()*0.1, 0.01)
if zoomlevel# < -30.0 then zoomlevel# = -30.0
if zoomlevel# > 0.0 then zoomlevel# = 0.0
if zoomlevel# = 0.0 then set alpha mapping on Object, 100.0
endif
ENDIF
IF MOUSECLICK() = 4 THEN FocusDistance=FocusDistance-MOUSEMOVEY()*0.25
if upkey()=1 then FocusDistance=FocusDistance+2.5
if downkey()=1 then FocusDistance=FocusDistance-2.5
if FocusDistance>FocusMinDistance then FocusDistance=FocusMinDistance
if FocusDistance<FocusMaxDistance then FocusDistance=FocusMaxDistance
move camera FocusDistance
if camera position y()<-30 then position camera camera position x(),-30,camera position z()
mousemovex()=0
mousemovey()=0
ENDFUNCTION
function fade_player_when_zoomed_in(obj, zoomlevel#, faderate#=0.01)
playerfade# = abs(playerfade#)
if object exist(obj)
if playerfade# > 0.0 then playerfade#=zoomlevel#-faderate#
set alpha mapping on obj, playerfade#
endif
endfunction zoomlevel#
I want to know why for some reason when you try to look up or down with the Orbit cam very slowly between -0.5 & 0.5 why the player disappears right in the middle of those sometimes. But when you rotate up or down after that, the player reappears like magic.
Thanks for help!
Sasuke
平和愛ユニティ