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 Discussion / Mouse look keeps returning back to looking straight ahead

Author
Message
Unseen Ghost
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 28th Jun 2012 05:15
Hi,

Every time I move the camera to look up or down, the camera returns back to looking straight ahead instead of staying up or down.

I noticed to CameraAngleX returns to 360 when I let go of the mouse. I also uploaded a picture. Can someone help?



Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 9400 GT(PNY)1GB Video/500GB Western Dig. HD/Dark Basic Pro 7.4

No one cares how much you know until they know how much you care.

Attachments

Login to view attachments
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 28th Jun 2012 05:39 Edited at: 28th Jun 2012 06:04
Typo!
Quote: "`STORE CAMERA ANGLE FOR MOUSE
CameraAngleX# = Wrapvalue(CameraAngle#X+mousemoveY())
CameraAngleY# = Wrapvalue(CameraAngleY#+mousemoveX())"

The resetting hints that it's only looking at mousemovey().

[edit]

You can do the camera look a bit simpler:

Since we are controlling the camera angle we don't need to use camera angle x() or ...y(). I stored the mousemove values for two reasons: it looks neater and I like to store all inputs in variables before doing anything with them just in case they change during processing. You don't necessarily have to do that as it's very unlikely but it does also get rid of those horribly long names.

Shh... you're pretty.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 28th Jun 2012 06:30 Edited at: 28th Jun 2012 07:44
You were so close to doing the movement a really good way. Again we don't need to get the camera position because we are controlling it.


Could be:

Note that both the new X and Z values use the CamAngY, both positions are on the same horizontal plane, moving along the plane is only affected by Y angle, no XZ rotation is required to move along a horizontal plane. If there were hills or you could fly the movement would be more complicated and likely include both X and Z rotation.

You can combine the forward and back movement as they deal with the same axis of movement.

Are you familiar with the keystate command? key_fwd and key_bck are just variables currently assigned 17 and 31 (W and S keys). WlkSpd# is another variable that holds the walking speed value for the player. It's good to set this sort of thing with a variable in case you want to change the value, you should have very few or even no bare numbers in your code if you want it to be easier to edit and read.

You can combine the strafing too.

I did a bit more editing to adjust the player's speed when strafing and walking at the same time -- he was moving twice as quickly since both actions move at full speed. I actually made an error here, not a fatal one but I could have done it better. Here's the whore subroutine (I changed it from a function so passing variables is easier), see if you can tell what could have been done better. Hint: Look for similar bits of code that could be combined, and about what direction the player is moving.


If you spotted it then I'm impressed because it is quite difficult to see.
The problem is that I'm messing around with the speed of the player at different angles and then combining the movements. I should have made the inputs adjust the angle of movement instead.

[I'll just do that now and post...]

Hmm I'm actually stuck here! It's harder than I thought.

Shh... you're pretty.
Unseen Ghost
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 1st Jul 2012 22:14
Thanks for your help, sorry I took so long with getting back and responding. I have had some family issues to deal with.

Yea I do want to simplify the code and combine things where I can. If I can do some programming tonight will examine your examples more thoroughly.

I will let you know how it goes.

Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 9400 GT(PNY)1GB Video/500GB Western Dig. HD/Dark Basic Pro 7.4

No one cares how much you know until they know how much you care.
Unseen Ghost
21
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Ohio
Posted: 24th Jul 2012 02:37
just thought I'd let you know I figured out why my mouse kept returning to looking straight ahead and wouldn't go past about a 45 degree angle.
I had to change this line:


To this:


I had to change where it said CameraAngle#X to CameraAngleX#

Gigabyte Board/2.93Ghtz Intel Core Duo Proc./4GB Ram/Nvidia Geforce 9400 GT(PNY)1GB Video/500GB Western Dig. HD/Dark Basic Pro 7.4

No one cares how much you know until they know how much you care.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Jul 2012 09:27
Yes, from the behaviour of the camera you can work that it is not taking the variable into account; and sure enough there is a simple spelling error. This is why it is important to display as much data as possible when testing because you wont always have a visible clue like this.

Shh... you're pretty.

Login to post a reply

Server time is: 2024-04-24 00:45:41
Your offset time is: 2024-04-24 00:45:41