WiiLi Wiki frontpage Include your post in the News Get links Hoteles Quito
WiiLi.org Forum Index WiiLi.org
a new revolution
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Roll and tilt script

 
Post new topic   Reply to topic    WiiLi.org Forum Index -> Wii Scripts
View previous topic :: View next topic  
Author Message
pipoxyz



Joined: 06 Jul 2007
Posts: 127

Digg It
PostPosted: Sat Jul 14, 2007 6:02 am    Post subject: Roll and tilt script

I made a roll and tilt script because somehow, the existing ballance and hamsterball scripts where not responsive enough..i ended up with a script thats usable in a more broader sense... i'll post in in wikki later, but because im such an absolute noob, i would like it if someone could check the script for errors, or perhaps has a suggestion before i post it
Code:

/*
Pipoxyz flip and roll V1.02
GlovePIE 0.29
PPJoy 0.83

Set PPJoy Virtual Joystick 1 to 2 analog axes and 11 digital buttons
to use joystick mode.

I'd say this script is a 60% compilation of other scripts.
The main reason for making it was because i just couldnt find
usable scripts for games like ballance or Hamsterball,
but i imagine it to be very usefull for plenty of other games like motor
or car racing or platform as well.

This script profides all 4 types of controls,
keyboard/joystick/mouse/directinput mouse under 1 joypad setting
You can switch between the modes by pressing plus or minus.
You might need to calibrate some modes individually.
All the values you might need to change are surrounded by bars.

Hold the wiimote in horizontal position like holding a nes controller.
with the dpad on the left side.

Roll the wiimote foreward for up, backward for down,
Tilt the wiimote left for left and right for right.

You can assign buttons and keys at the bottom of the script,
The keys assigned to them atm do not make a lot of sense

Known problems are:
If you keep a joystick button pressed while switching modes,
it will keep that button pressed

Things i wanted a bit different are:
wanted all switches under 1 button..couldnt find out how.
wanted deadzones and acceleration for all types, but the scripts i could
come up with for window mouse and joystick where to unprecise so i removed it.
*/



//Sensitivity. Lower means more sensitive. 1 = full range.
//----------------------------------------------------------------------------\\
//1 = 180 degree range, 0.5 = 90 degree range, etc.                           \\
var.sensey = 0.75 //sensitivity joystick                                      \\
var.sensem1 = 0.75 //sensitivity direct input mouse                           \\
var.sensem2 = 0.75 //sensitivity windows mouse                                \\
var.sensek = 0.75 //sensitivity keyboard                                      \\
//----------------------------------------------------------------------------\\
var.dirspeedm1 = 80      //multiplier speed directmouse                       \\
//----------------------------------------------------------------------------\\
var.deadzonem1 = 0.02 //minimal movement for directinput,set to 0 to disable  \\
var.deadzonek = 0.2   //minimal movement for keyboard,set to 0 to disable     \\
//----------------------------------------------------------------------------\\
//enabling ,directinput mouse acceleration makes the mouse move slower        \\
var.enableacc = true  //enable/disable mouse acceleration for directmouse     \\
var.accm1 = 1 //multiplier mouse acceleration for directmouse                 \\
//CALIBRATION. Press Run and use the debug window to enter the numbers        \\
//----------------------------------------------------------------------------\\
var.xmin = 0.96 // Place remote on left side. Enter number from GX            \\
var.xmax = -1.02  // Place remote on right side. Enter number from GX         \\
var.ymin = 1  // Place remote lying flat, buttons down. Enter number from GY  \\
var.ymax = -1.06 // Place remote lying flat, buttons up. Enter number from GY \\
//----------------------------------------------------------------------------\\
var.speakmode = true //enable/disable speech                                  \\
//Offset is to center the crosshair..                                         \\
//----------------------------------------------------------------------------\\
var.xoffsety = 0 //Center X Axis Joystick                                     \\
var.yoffsety = 0 //Center Y Axis Joystick                                     \\
var.xoffsetm2 = 12 //Center X Axis Windows Mouse                              \\
var.yoffsetm2 = 8 //Center Y Axis Windows Mouse                               \\
//----------------------------------------------------------------------------\\
//Smoothes out the GX and GY values
var.x = smooth(Wiimote.gZ)
var.y = smooth(Wiimote.gX)

//assign different control modes to plus and minus.
   if Clicked(Wiimote.Minus)
      if var.directinput
         var.directinput = false
         var.joymode = false
         var.keymode = false
         if var.SpeakMode then Say "Normal Mouse Mode"
         var.mousemode = true
      else
         var.mousemode = false
         var.directinput = true
         var.joymode = false
         var.keymode = false
         if var.SpeakMode then Say "Directinput Mouse Mode"
      endif
   endif
   if Clicked(Wiimote.Plus)
      if var.joymode
         var.joymode = false
         var.directinput = false
         var.mousemode = false
         if var.SpeakMode then Say "Key board Mode"
         var.keymode = true

      else
         var.joymode = true
        // var.joymode = false
         var.keymode = false
         var.directinput = false
         var.mousemode = false
       if var.SpeakMode then Say "Joystick Mode"
      endif
   endif
//Joystick Mode///////////////////////////////////////////////////////////////
if var.joymode = true

//Assigns the sensitivity
var.xminy = var.xmin*var.sensey
var.xmaxy = var.xmax*var.sensey
var.yminy = var.ymin*var.sensey
var.ymaxy = var.ymax*var.sensey

//offsets joystick
var.xoffsety = var.xoffsety/30
var.yoffsety = var.yoffsety/30

//Assigns Offset joystick
var.xy = var.x + var.xoffsety
var.yy = var.y + var.yoffsety

//assign maprange joystick
ppjoy.analog0 = MapRange(var.xy, var.xminy, var.xmaxy, 1, -1)
ppjoy.analog1 = MapRange(var.yy, var.yminy, var.ymaxy, 1, -1)

endif
//directinput mouse Mode//////////////////////////////////////////////////////
if var.directinput = true

//assign sensibility directmouse
var.xminm1 = var.xmin*var.sensem1
var.xmaxm1 = var.xmax*var.sensem1
var.yminm1 = var.ymin*var.sensem1
var.ymaxm1 = var.ymax*var.sensem1

//mouse acceleration directmouse
if var.enableacc = true
if var.x < 0
var.rotationxm1 = -var.x * var.accm1
endif
if var.x > 0
var.rotationxm1 = var.x * var.accm1
endif
if var.y < 0
var.rotationym1 = -var.y * var.accm1
endif
if var.y > 0
var.rotationym1 = var.y * var.accm1
endif
endif
//disable mouse acceleration
if var.enableacc = false
var.rotationxm1 = 1
var.rotationym1 = 1
endif
//assign maprange directmouse
if var.x >= var.deadzonem1 or <= -var.deadzonem1 {
mouse.DirectInputX = mouse.DirectInputX + var.dirspeedm1 * var.rotationxm1 * MapRange(var.x, var.xminm1, var.xmaxm1, 1, -1)
}
if var.y >= var.deadzonem1 or <= -var.deadzonem1 {
mouse.DirectInputY = mouse.DirectInputY + var.dirspeedm1 * var.rotationym1* MapRange(var.y, var.yminm1, var.ymaxm1, 1, -1)
}
endif
mouse.leftbutton = Wiimote.A   //                                             \\
mouse.rightbutton = Wiimote.B  //                                             \\
key.home = Wiimote.Home        //                                             \\
key.w = Wiimote.Up             //                                             \\
key.s = Wiimote.Down           //                                             \\
key.a = Wiimote.Left           //                                             \\
key.d = Wiimote.Right          //                                             \\
key.enter = Wiimote.One        //                                             \\
key.esc = Wiimote.Two          //   
//Normal mouse Mode //////////////////////////////////////////////////////////
if var.mousemode = true

//offsets normalmouse
var.xoffsetm2 = var.xoffsetm2/30
var.yoffsetm2 = var.yoffsetm2/30

//assign offsets
var.xm2 = var.x + var.xoffsetm2
var.ym2 = var.y + var.yoffsetm2

//assign sensibility normal mouse
var.xminm2 = var.xmin*var.sensem2
var.xmaxm2 = var.xmax*var.sensem2
var.yminm2 = var.ymin*var.sensem2
var.ymaxm2 = var.ymax*var.sensem2

//assign maprange normal mouse
mouse.X = MapRange(var.xm2, var.xminm2, var.xmaxm2, 1, -1)
mouse.Y = MapRange(var.ym2, var.yminm2, var.ymaxm2, 1, -1)
endif
mouse.leftbutton = Wiimote.A   //                                             \\
mouse.rightbutton = Wiimote.B  //                                             \\
key.home = Wiimote.Home        //                                             \\
key.w = Wiimote.Up             //                                             \\
key.s = Wiimote.Down           //                                             \\
key.a = Wiimote.Left           //                                             \\
key.d = Wiimote.Right          //                                             \\
key.enter = Wiimote.One        //                                             \\
key.esc = Wiimote.Two          //   
//Keyboard Mode //////////////////////////////////////////////////////////////
if var.keymode = true

//Assigns the sensitivity
var.xmink = var.xmin*var.sensek
var.xmaxk = var.xmax*var.sensek
var.ymink = var.ymin*var.sensek
var.ymaxk = var.ymax*var.sensek

//assign maprange keyboard
if var.x >= var.deadzonek or <= -var.deadzonek {
var.KeybX = MapRange(var.x, var.xmink, var.xmaxk, 1, -1)
} elseif wiimote.gz < var.deadzonek or > -var.deadzonek
var.KeybX = 0
endif
if var.y >= var.deadzonek or <= -var.deadzonek {
var.KeybY = MapRange(var.y, var.ymink, var.ymaxk, 1, -1)
}  elseif wiimote.gx < var.deadzonek or > -var.deadzonek
var.KeybY = 0
endif

  var.jx = var.KeybX + var.LeftOverX
  var.jy = var.KeybY + var.LeftOverY

if var.jx > 1 then
  var.LeftOverX = Var.jx - 1.0
  var.LeftKey = false
  var.RightKey = true
else if var.jx < -1 then
  var.LeftOverX = Var.jx + 1.0
  var.RightKey = false
  var.LeftKey = true
else
  var.LeftOverX = Var.jx
  var.LeftKey = false
  var.RightKey = false
end if

if var.jy > 1 then
  var.LeftOverY = Var.jy - 1.0
  var.UpKey = false
  var.DownKey = true
else if var.jy < -1 then
  var.LeftOverY = Var.jy + 1.0
  var.DownKey = false
  var.UpKey = true
else
  var.LeftOverY = Var.jy
  var.UpKey = false
  var.DownKey = false
endif
//Key and button assignments
//----------------------------------------------------------------------------\\
//assign keys for keyboard mode//                                             \\
Key.up = var.UpKey             //                                             \\
Key.down = var.DownKey         //                                             \\
Key.left = var.LeftKey         //                                             \\
Key.right = var.RightKey       //                                             \\
key.home = Wiimote.Home        //                                             \\
key.w = Wiimote.Up             //           z                                  \\
key.s = Wiimote.Down           //                                             \\
key.a = Wiimote.Left           //                                             \\
key.d = Wiimote.Right          //                                             \\
key.enter = Wiimote.One        //                                             \\
key.esc = Wiimote.Two          //                                             \\

//----------------------------------------------------------------------------\\
//assign digital buttons joystick                                             \\
if var.joymode                 //                                             \\
ppjoy.digital0 = Wiimote.A     //                                             \\
ppjoy.digital1 = Wiimote.B     //                                             \\
ppjoy.digital2 = Wiimote.Home  //                                             \\
ppjoy.digital5 = Wiimote.Up    //                                             \\
ppjoy.digital6 = Wiimote.Down  //                                             \\
ppjoy.digital7 = Wiimote.Left  //                                             \\
ppjoy.digital8 = Wiimote.Right //                                             \\
ppjoy.digital9 = Wiimote.One   //                                             \\
ppjoy.digital10 = Wiimote.Two  //                                             \\
endif                          //                                             \\
//if no joystick selected, recenter joystick                                  \\
if var.joymode = false         //                                             \\
ppjoy.analog0 = 0              //                                             \\
ppjoy.analog1 = 0              //                                             \\
endif                          //                                             \\
//----------------------------------------------------------------------------\\


//----------------------------------------------------------------------------\\
//LEDs
if wiimote.roll <= -90
   Wiimote.Leds = 8
elseif wiimote.roll <= -60
   Wiimote.Leds = 4 + 8
elseif wiimote.roll <= -30
   Wiimote.Leds = 4
elseif wiimote.roll <= 0
   Wiimote.Leds = 2 + 4
elseif wiimote.roll >= 90
   Wiimote.Leds = 1
elseif wiimote.roll >= 60
   Wiimote.Leds = 1 + 2
elseif wiimote.roll >= 30
   Wiimote.Leds = 2
elseif wiimote.roll >= 0
   Wiimote.Leds = 2 + 4
else
   Wiimote.Leds = 0
endif
endif

//Debug Line
debug = 'GX: ' + Wiimote.gx + ' GY: ' + Wiimote.gz


Last edited by pipoxyz on Tue Jul 24, 2007 6:13 am; edited 2 times in total
Back to top
View user's profile Send private message
unreal2k8



Joined: 17 Jul 2007
Posts: 3

Digg It
PostPosted: Tue Jul 17, 2007 8:48 pm    Post subject:

sweet, thanks i hope you dont mind i stole a bit of your script, im using it to make a cool resident evil script
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    WiiLi.org Forum Index -> Wii Scripts All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group