Help with mouselook function.

Blitz3D Forums/Blitz3D Beginners Area/Help with mouselook function.

Irvau(Posted 2015) [#1]
I need help with a mouselook/freelook function I tried to write a little while ago.
I looked around on the forums for some examples of this, and mimicked those.
The following is what I came up with. It comes in two bb files.

"main.bb"


And the "Player.bb" file.


However, when I run this stuff, I can't turn the camera as I wish it to. I look over the code, but I can't find the error in it.
Help, anyone? Thanks in advance!


Matty(Posted 2015) [#2]
As far as I can see dt is a local variable and is always zero. ...

Also youve spelled default incorrectly in your zoom setting.


Irvau(Posted 2015) [#3]
*derp*

Yup, that "DefaultZoom" thing sure does help. I copied and pasted only the important parts of the code into this, so I missed a few things.

"DefaultZoom" was a constant declared to be 1.

Oh, and "dt" was a shortened variable for a DeltaTime() function. Forgot to include it here;


But, yeah, "dt" had been treated as a local in both functions, as I had forgotten to declare it as a global. :P

Thanks for the help!


Irvau(Posted 2015) [#4]
Well....

I've added/fixed the code mentioned above, but I still can't turn the camera. It seems like it *tries* to turn the camera, only to fail and return the position in which it started out with.

:|


RGR(Posted 2015) [#5]
I may be wrong, but it seems you are making the mistake nearly all newbies to Blitz3D are doing.
You pick some code from advanced coders and want to make a game in 10 Minutes.
Instead of spending some hours learning the basics first.

Blitz3D comes with a help section. And other than in most other languages each Command in the Helpfiles comes with a working example code snippet.

So instead of asking questions, just start with the examples und you will after some days understand what you made wrong and how to make it right..
Otherwise you will ask and ask and ask questions until you give up coding.
Some of the newbies have 200 posts in 2 months after starting their *gamemaker carrier* here ... they still ask dumb questions, because they think the community is there to code their games ...
But that's wrong ... you get help en masse ... but you must be willing to understand the language first ... teaching yourself from example code and the tutorials ... blitz3d is more than 10 years old and there are millions of code lines all over this forum. They help you to get the basics into your head.
You'll never get far when you seek the easy way: each time asking other people to solve your problems.

We, the few veterans who were here from the start, who are more than 10 years watching the forum see the *gamemakers* come and go ... some are here 2 years, produced 2000 posts, are copying and pasting code and still don't know how to program a game ... others are here for 1 or 2 month ... asking questions each day and then they vanish forever ... obviously found out that they don't have the ability to code ...

If you don't find an error yourself in a piece of code that is less than 50 lines small, you will never be able to code a game with 1000 or even 10000 lines of code ...


Irvau(Posted 2015) [#6]
I appreciate your concern. Sorta. Not really. :|

Anyways, to answer some of your woes, I understand how to use Blitz3D very well. I wouldn't say to the full extent, but I know at least the basics.
Plus, I know what's going on in that piece of code up there. It gets the movement of the mouse, multiplies it by a turning speed factor, adds that difference to the current pitch and yaw values, applies "smoothature" to it, and then makes the camera turn by that much. The only reason I came here is because I looked over this thing 40+ times trying to fix it. Some fixed typos did help with certain aspects, but still other bugs remained. So, yeah, I came here. I'm not expecting the community to solve it all for me - I actually *tried* to fix it before coming here.

I must admit, that's true, it's kinda sad I can't fix a simple mouselook function. That's part of the reason for my frustration.

Usually the error is one misspelled variable or something that I constantly look over until I've tried everything else.


Irvau(Posted 2015) [#7]
Oh, and I also found the error from the thing above.

I needed to declare Pitch# and Yaw# as a global.

._.

Oh, and the code needed to be included in the main loop. Otherwise, the two values would lose their values as the function was run through. Or "if" statement, as well.

What sucks though, is that I was hoping to allow it to be a function. I really, really, REALLY hate having this code in my main loop. It annoys the crap out of me; I'd rather have it in a nice function gathered along with other nice little functions for the player controls.


RemiD(Posted 2015) [#8]
If you provide a simple scene to be able to test your code i will take a look later.
Also take a look at this example :
http://www.blitzbasic.com/codearcs/codearcs.php?code=2933


Irvau(Posted 2015) [#9]
Thanks for the example! I could use it. :)

However, I've figured it out, so there's no need to take a look. It can stay in a function if all of the variables involved are declared as globals.

But if you're determined to test it out, here's a simple, common "random box landscape" terrain:
Dim cube(200)
For n=1 To 200
cube(n) = CreateCube()
ScaleEntity cube(n), Rand(1,50),Rand(1,50),Rand(1,50)
PositionEntity cube(n), Rand(-1000,1000),Rand(-1000,1000),Rand(-1000,1000)
Next

:P


Matty(Posted 2015) [#10]
You can pass parameters to functions......just saying.....


RemiD(Posted 2015) [#11]

I've figured it out, so there's no need to take a look.


Ok, good !


It can stay in a function if all of the variables involved are declared as globals.


Yes, sometimes a global can be useful to access a variable from everywhere.

It is considered a bad practice by some coders but if you know what you are doing, there is no problem to use some globals, just make sure you will not reuse the same variable name by mistake in others parts of the program.