Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Walking in camera's dirrection

Author
Message
Guitarussia
14
Years of Service
User Offline
Joined: 16th Nov 2011
Location: NH, USA
Posted: 16th Nov 2011 11:29
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!



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
Mr Bigglesworth
18
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 16th Nov 2011 15:15
You can use the command MOVE CAMERA to move the camera in the direction it is pointing.
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 16th Nov 2011 20:51 Edited at: 16th Nov 2011 20:53
@Guitarussia

Mr Bigglesworth is right. You can do it with x#=wrapvalue(x#,angle,speed), but with move commands goes super. I made some changes to your code that are marked with )))))))))))))))))) to show my corrections. Take a look.



Cheers.

I'm not a grumpy grandpa
Guitarussia
14
Years of Service
User Offline
Joined: 16th Nov 2011
Location: NH, USA
Posted: 18th Nov 2011 20:29
Thank you guys, your corrections worked perfectly. But I decided to take a different approach. Looking at one of the code snippets I realized that I can use trigonometric functions sin and cos to calculate my x# and y# values:
if keystate(17) = 1
  inc x#, sin(cay#) * move_speed#
  inc z#, cos(cay#) * move_speed#
endif
if keystate(30) = 1
  dec x#, sin(cay# + 90) * move_speed#
  dec z#, cos(cay# + 90) * move_speed#
endif
if keystate(31) = 1
  dec x#, sin(cay#) * move_speed#
  dec z#, cos(cay#) * move_speed#
endif
if keystate(32) = 1
  dec x#, sin(cay# - 90) * move_speed#
  dec z#, cos(cay# - 90) * move_speed#
endif


cay# simply stores the camera angle y() return value multiplied by a mouse_sensitivity# variable to adjust the camera's rotation speed. For front/backward movement I take the sin(cay#) to calculate the x-value and the cos(cay#) to calculate y-value. To calculate positions directly left/right of the camera, I simply need to add/subtract 90 degrees. I use the y-angle of the camera because the y-axis determines left/right rotation.
I then use these calculated values to move my camera:

position camera 1, x#, y# + get ground height (3, x#, z#), z#
[\code]

And lastly I rotate the camera using the adjusted camera angle x and camera angle y variables, leaving z-axis alone because I don't need to touch it:

rotate camera cax#, cay#, camera angle z


I like this process better simply because it make mathematical sense to me. It also enables strafing left and right. I hope this helps somebody out there.

Thank you both, I like your method as well, it is neat and short.

Inspired, waiting to be enlightened
Daniel wright 2311
User Banned
Posted: 18th Nov 2011 23:41
move camera with arrow keys

this is a command.

my signature keeps being erased by a mod So this is my new signature.

Login to post a reply

Server time is: 2026-07-10 16:32:57
Your offset time is: 2026-07-10 16:32:57