Link102,
First, there is no need for this line of code:
xangle#=camera angle x()
yangle#=camera angle y()
xangle#=wrapvalue(xangle#+roty#)
yangle#=wrapvalue(yangle#+rotx#)
, and you need to remove
if rotlimit=0 then rotx#=mousemovex() and keep
`if rotlimit=0 then rotx#=wrapvalue(rotx#+mousemovey()), but without the
` symbol.
Now, notice that you have two variables using the same mouse move command. There is
rotx# and
roty# which both feed from the same hole.
rotx# is 'meant' to be for the camera's
x amount of rotation, and
roty# for it's
y amount of rotation. Therefore, they cannot both be recieving the mouse's y movement. So, change
roty#=mousemovey() to
roty# = wrapvalue(roty# + mousemovex()). I've changed
mousemovey() to
mousemovex().
Wrapvalue is very important if so-be that an angle will go over 360o or under 0o. Also, I have added
...(roty# + mousemovex()), because without it you will never be able to rotate more than a few degrees.
Mousemove returns a negative or a positive number, depending on the direction of the movement. On the Y dimension, moving your mouse up will create a negative value, and down will return a posiive value. Same for the X dimension:left a negative and right a positive. So, do the math here.
Lastly, change
rotate camera xangle#,yangle#,0 to
rotate camera rotx#,roty#,0, because
rotx# and
roty# are the variables which should now be holding the correct information for your camera to rotate correctly.
In conclusion, the code you have added disfunctioned the entire result. On top of this, you included code(the first lines of code I mentioned) that were cumbersome and not needed. Stick to the code I originally sufficed you(
if rotlimit = 0 then rotx# = wrapvalue(rotx# + mousemovey())
if rotx# < 315 and rotx# > 200
rotx# = 315
rotlimit = 1
endif
if rotx# > 45 and rotx# < 160
rotx# = 45
rotlimit = 1
endif
if rotx# = 315 and mousemovey() > 0 then rotlimit = 0
if rotx# = 45 and mousemovey() < 0 then rotlimit = 0
xrotate camera rotx#
yrotate camera roty#
), without adding any extras, and your rotation will be fine.
When in a rut with your code, which is not acting as should, run through your code, line by line, creating a mental animation of a certain scenario ran by your code. This is a great method which helps me, at least, to figure what might be wrong in my program.
+NanoBrain+