Topic: Mouse Look question

Hello I have used this script (look below) for mouse look on my game(test), however i am faced with a problem where i can only move side ways so far, and I cannot do a 360 view. can i get some help here?

by the way I took this example from the Video tutorials from special_ops (great tutorials by the way)

<code>
-- Global Variables
dx = 0.0
dy = 0.0
centerCursor()
my = getAxis("MOUSE_Y")
mx = getAxis("MOUSE_X")
-- stuff
hideCursor()

function MoveAround()

    -- look around
    -- X Axis
    rotate(Player, {0, 0, -1}, dx*100)

    -- Y Axis
    rotate(Head, {1, 0, 0}, dy*100, "local")
    rotation = getRotation(Head)
       
    if rotation[1]>90 then
        rotation[1] = 90
    elseif rotation[1] < -90 then
        rotation[1] = -90
    end   
       
    -- get new mouse position
    dx = getAxis("MOUSE_X") - mx
    dy = getAxis("MOUSE_Y") - my
   
    -- center cursor
    --centerCursor()
   
    mx = getAxis("MOUSE_X")
    my = getAxis("MOUSE_Y")
</code>

Re: Mouse Look question

Thanks (: The problem here is that you have quoted out the centerCursor() function; just remove the -- in front of it and it should work fine (assuming that this is just an extract from your script).

Last edited by special_ops (2012-10-28 16:33:59)

Re: Mouse Look question

Thanks for the suggestion, however, i now remember why i commented the centerCursor() function, if i enable it, there is no mouse look at al :S.
I am 100% new to game dev (to be honest even to programming at all) just trying to learn using all these incredibly useful tools.

I added a print to the text the output mx and noticed it only changes from 0 to close to 1 (0.9999) so i am guessing MOUSE_X is float that only accepts 0 to 1.

to expliain a bit more, my camera is attached to Head much like in the video tutorial, however my function does not reside directly in onScreenUpdate, it's a separate function (for organization and learning experience).

I also tried moving the centerCursor() to the onScreenUpdate main function, but same result, moving the mouse does nothing :S a bug on Maratis on linux? or just my newbie issues?

Re: Mouse Look question

i think i solved my problem, and this might be a bug in linux (not sure) but it seems that the mouse update was not as quick as the scene update hence it would seem to not register the move of the mouse.

I use this  see below (stole the idea from another thread that was asking how to add timers), i still need to tweak the time it takes to update so it does not look so jumpy.

-- center cursor
    if t == 20  then
    centerCursor()
    t = 0
    end
t = t + 1

Re: Mouse Look question

Final Update on this chapter big_smile it truns out i did not need to add the timer to the cursor update, what needed to do was to disable the compositor features of xfce (i use xubuntu) it seems that when compositing is enabled, the centercursor function does not work as expected.

this may or may not apply to other compositors