Posted: 17th Jun 2007 23:23
Hello all, I'm encountering a problem that is stumping me. I've tried to wrap the value of the angle, but it still reverses. What I'm doing is using the set camera to follow command. I have it set up so when I hold the control key, the camera rotates around using the mouse, and that works fine when it IS NOT wrapped. If I leave go of the control key, it's supposed to follow the object's rotation, which it does, but it then reverses direction... any clues?
Posted: 17th Jun 2007 23:31
What do you mean by "reverses direction" exactly? My first impression is gimble locking, but I've no clue if that's what you mean.
Posted: 17th Jun 2007 23:40
ok, what happens is the camera rotates with the player, staying behind the player, then after the player has turned about 360 degrees, the camera rotates the opposite of the player.

[EDIT]
It reverses at 180 degrees.
Posted: 17th Jun 2007 23:42
Below is the playercontrol function I use.

+ Code Snippet
function playercontrol()
    playerdata(1).posx=object position x(1)
    playerdata(1).posy=get ground height(1,object position x(1),object position z(1))+object size y(1)/2
    playerdata(1).posz=object position z(1)
    if controlkey()=1
        mangle#=mousex()
        smoothingm=85
    else
        if controlkey()=0
            mangle#=object angle y(1)
            smoothinm=0
        endif
    endif 
    set camera to follow playerdata(1).posx,playerdata(1).posy,playerdata(1).posz,mangle#,15,15,smoothingm+15,1
    position object 1,playerdata(1).posx,playerdata(1).posy,playerdata(1).posz
    if upkey()=1 or keystate(17)=1
        move object 1,1
    else
        if downkey()=1 or keystate(31)=1
            move object 1,-1
        endif
    endif
    if leftkey()=1 or keystate(30)=1
        turn object left 1,.5
    else
        if rightkey()=1 or keystate(32)=1
            turn object right 1,.5
        endif
    endif        
endfunction
Posted: 18th Jun 2007 0:36
Attached is the exe of it. Click New Game, Type any name, press enter, use arrow keys/WASD to turn, use controlkey and mouse to free rotate.
Posted: 18th Jun 2007 1:59
If I remember well the turn command does not properly set the object y angle ( it remains unaffected ).

print your mangle# on screen at runtime and you 'll see it never changes when you turn with the keys
Posted: 18th Jun 2007 2:24
but the camera still turns oddly...
Posted: 18th Jun 2007 3:22
thanks, that cleared it up

Another question. When it transfers from mouse control to object control the screen "tears" and it looks quite bad. How would I smooth the angle from the mouse position to the object's angle?
Playercontrol function below.

+ Code Snippet
function playercontrol()
    playerdata(1).posx=object position x(1)
    playerdata(1).posy=get ground height(1,object position x(1),object position z(1))+object size y(1)/2
    playerdata(1).posz=object position z(1)
    if controlkey()=1
        if mousex()>0 and notpressed=1
            notpressed=0
            position mouse 0,mousey()
        endif
        smoothingm=85
        mangle#=mousex()
    else
        if controlkey()=0
            mangle#=object angle y(1)
            notpressed=1
        endif
    endif
    text 5,5,str$(smoothingm)
    text 5,25,str$(object angle y(1)) 
    text 5,45,"Wrapped: "+str$(wrapvalue(object angle y(1))) 
    set camera to follow playerdata(1).posx,playerdata(1).posy,playerdata(1).posz,mangle#,25,15,smoothingm+15,1
    position object 1,playerdata(1).posx,playerdata(1).posy,playerdata(1).posz
    if upkey()=1 or keystate(17)=1
        move object 1,.25
    else
        if downkey()=1 or keystate(31)=1
            move object 1,-.25
        endif
    endif
    if leftkey()=1 or keystate(30)=1
        dec playerdata(1).roty,.25
        rotate object 1,playerdata(1).rotx,playerdata(1).roty,playerdata(1).rotz
    else
        if rightkey()=1 or keystate(32)=1
            inc playerdata(1).roty,.25
            rotate object 1,playerdata(1).rotx,playerdata(1).roty,playerdata(1).rotz
        endif
    endif        
endfunction


Thanks in advance.

[EDIT]
And another question. Using randomize, could I specify a certain random set of numbers so a matrix will always be the same?
Posted: 18th Jun 2007 18:12
bump
Posted: 18th Jun 2007 22:19
It tears because at one time you affect mangle# with mousex() (when ctrlkey=1) and at another time you force mangle# to suddenly become the object y angle.
You should base all your conditions on affecting the player y angle

you should do something along these lines:

if ctrlkey=1
mymousex=mousemovex()
if mymousex>0 then playeryangle#=wrapvalue(playeryangle#+1,0)
if mymousex<0 then playeryangle#=wrapvalue(playeryangle#-1,0)
endif
if ctrlkey=0
if leftkey()=1 then playeryangle#=wrapvalue(playeryangle#-1,0)
if rightkey()=1 then playeryangle#=wrapvalue(playeryangle#+1,0)
endif

yrotate player to playeryangle#

- set camera to follow player -

my 2 cents
Posted: 20th Jun 2007 1:49
thanks scorpyo, but I decided on using curveangle...