Hello!
I am new to Dark Basic Pro, I have about 2 weeks of experience now. I am working on a first-person camera and I am happy with what I have so far. I have made the camera move in all directions, I have made it jump, and I just started incorporating mouselook. However, I ran into a problem that I have been losing sleep over:
I can use the mouse to look in all directions, and I can move my camera in all directions. But I cannot move my camera in the detection that it is pointing!
I have written and re-written this code many times in the last 2 days, and now I have to turn for help. Below is my source code with full description of the logic I am working on for each statement. The mouselook portion is the first one in the main loop. If you see something that I am missing, please point it out!
rem Synchronization, refresh rate, autocam, hide cursor.
sync on
sync rate 60
autocam off
hide mouse
rem make player object
make object cube 61, 50
rem loop 60 times, each loop create a new cube and position that cube randomly, then exit loop.
for x = 1 to 60
make object cube x, 50
position object x, rnd(3000), 0 , rnd(3000)
next x
rem variable used to determine at which rate the camera moves (when added to an axis).
global move_speed# = 4.0
rem gravity variables used to determine camera's real-time Y position when jumping.
global gravity# as float
global gravity_pull# as float
rem the x, y, z positions of the camera will be stored in these variables
global y# = 0
global x# = 0
global z# = 0
global mouse_sensitivity# = 0.2
REM MAIN LOOP
do
REM mouse look test
position mouse screen width()/2,screen height()/2
MMX# = MouseMoveX() * mouse_sensitivity# : MMY# = MouseMoveY() * mouse_sensitivity#
CAX# = CAX# + MMY#
CAY# = CAY# + MMX#
if CAX# > 85 then CAX# = 85
if CAX# < -85 then CAX# = -85
rotate camera 0,CAX#,CAY#,0 `rotates the camera
rem Input for W,A,S,D keys to move camera foreward, left, back, right
if keystate(17) = 1 then z# = z# + move_speed#
if keystate(30) = 1 then x# = x# - move_speed#
if keystate(31) = 1 then z# = z# - move_speed#
if keystate(32) = 1 then x# = x# + move_speed#
rem Space bar imput to simulate a jump
if spacekey() = 1 and gravity# = 0.0
gravity# = 5.0
gravity_pull# = 0.2
endif
rem Each loop, the gravity# variable will be decremented by the gravity_pull# variable
dec gravity#, gravity_pull#
inc y#, gravity#
rem To make sure the camera does not fall through the ground
if y# < 0
gravity# = 0.0
gravity_pull# = 0.0
endif
rem update the camera's position
position camera x#, y#, z#
rem Refresh screen.
sync
loop
Thank you for your help in advance, and please excuse my English, I will try to clarify anything you ask.
Inspired, waiting to be enlightened