Wiimote & Nunchuck WASD help

Official forum for open source FreePIE discussion and development.
Post Reply
BoredGamerUK
One Eyed Hopeful
Posts: 2
Joined: Tue Sep 02, 2014 1:48 pm

Wiimote & Nunchuck WASD help

Post by BoredGamerUK »

Hey guys I am building a VR set up for a Charity Live Stream form FPS stuff like Half-Life 2 and DayZ, we are planning to use Wii Remote Plus & Nunchucks using FreePie.
I have no idea how to script anything, has anyone made a Wiimote Script for a FPS game or a Working WASD / Gamepad emulator?
Thanks peeps!
BoredGamerUK
One Eyed Hopeful
Posts: 2
Joined: Tue Sep 02, 2014 1:48 pm

Re: Wiimote & Nunchuck WASD help

Post by BoredGamerUK »

More specifically I want the wii mote to control the mouse/gun
The Nunchuck joystick WASD/Gamepad
B - Left Click
Z - Press E
A - Press R
C - Space
Wii Remote Up,Down,Left,Right - Press 1,2,3,4
1 - SHIFT
2 - Press Q

Using a Wiimote Plus
NoxWings
One Eyed Hopeful
Posts: 44
Joined: Thu May 15, 2014 8:04 am

Re: Wiimote & Nunchuck WASD help

Post by NoxWings »

BoredGamerUK wrote:More specifically I want the wii mote to control the mouse/gun
The Nunchuck joystick WASD/Gamepad
B - Left Click
Z - Press E
A - Press R
C - Space
Wii Remote Up,Down,Left,Right - Press 1,2,3,4
1 - SHIFT
2 - Press Q

Using a Wiimote Plus
I don't own a wiimote but I think this script should cover pretty much it except from the wiimote mouse emulation. I'm not exactly sure yet how you want to use it.
On the other hand I'm assuming that nunchuck joysticks values are in range -1 to +1

Code: Select all

def wiimoteButtonUpdates:
	# A, B buttons
	mouse.leftButton = wiimote[0].buttons.button_down(WiimoteButtons.B)
	keyboard.setKey( Key.R, wiimote[0].buttons.button_down(WiimoteButtons.A) )
	
	# Dpad controls
	keyboard.setKey( Key.D1, wiimote[0].buttons.button_down(WiimoteButtons.DPadUp) )
	keyboard.setKey( Key.D2, wiimote[0].buttons.button_down(WiimoteButtons.DPadDown) )
	keyboard.setKey( Key.D3, wiimote[0].buttons.button_down(WiimoteButtons.DPadLeft) )
	keyboard.setKey( Key.D4, wiimote[0].buttons.button_down(WiimoteButtons.DPadRight) )
	
	# 1,2 buttons
	keyboard.setKey( Key.LeftShift, wiimote[0].buttons.button_down(WiimoteButtons.One) )
	keyboard.setKey( Key.Q, wiimote[0].buttons.button_down(WiimoteButtons.Two) )

def nunchuckUpdate():
	# Nunchuck stick update
	y = wiimote[0].nunchuck.stick.y
	x = wiimote[0].nunchuck.stick.x
	
	keyboard.setKey(Key.W, (y >= stickDeadZone))
	keyboard.setKey(Key.S, (y <= -stickDeaZone))
	keyboard.setKey(Key.D, (x >= stickDeadZone))
	keyboard.setKey(Key.A, (x <= -stickDeadZone))

	# Nuncuck C Z buttons
	keyboard.setKey( Key.Space, wiimote[0].nunchuck.buttons.button_down(NunchuckButtons.C) )
	keyboard.setKey( Key.E, wiimote[0].nunchuck.buttons.button_down(NunchuckButtons.Z) )


if starting:
	system.setThreadTiming(TimingTypes.HighresSystemTimer)
	system.threadExecutionInterval = 2
	
	stickDeadZone = 0.20

	wiimote[0].buttons.update += wiimoteButtonUpdates
	wiimote[0].nunchuck.update += nunchuckUpdate
Test the buttons update and I'll check the mouse look later.
Last edited by NoxWings on Wed Sep 03, 2014 10:18 am, edited 1 time in total.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Wiimote & Nunchuck WASD help

Post by CyberVillain »

For both nunchuck and mplus data the script needs to run at 500hz, its really bad that we require the user to know this, but thats how it is for now

so you need add

Code: Select all

system.setThreadTiming(TimingTypes.HighresSystemTimer)
system.threadExecutionInterval = 2
To the if starting closure
NoxWings
One Eyed Hopeful
Posts: 44
Joined: Thu May 15, 2014 8:04 am

Re: Wiimote & Nunchuck WASD help

Post by NoxWings »

CyberVillain wrote:For both nunchuck and mplus data the script needs to run at 500hz, its really bad that we require the user to know this, but thats how it is for now

so you need add

Code: Select all

system.setThreadTiming(TimingTypes.HighresSystemTimer)
system.threadExecutionInterval = 2
To the if starting closure
Ups thx cyber, fixed.

@BoredGamerUK
Test if the script button mapping is actually working, I can't test it so It may be completely wrong xD
User avatar
DonLuigi
One Eyed Hopeful
Posts: 1
Joined: Sun Aug 31, 2014 12:02 pm

Re: Wiimote & Nunchuck WASD help

Post by DonLuigi »

Hi,

This is my first post in the whole forum and I think I should introduce myself first. I just discovered FreePie when trying to get an RVL-CNT-01-TR controller to work like a mouse, and with it I also found this awesome forum.

I am not a programmer, nor a native english speaker, so you guys will have to bear me (I won't be any trouble though).

I did an script to play with Skyrim, I haven't had time to test it yet (I just know that the keys are working in fact), and I will post a modified version of it here, that may suit your needs.

In the original script I set a key to be the "mouse enabler". But for an FPS I think that, this is not an option, so I removed it. Would be nice if somebody could help setting a key to center the aim in the middle of the screen, because as there's no IR support yet, aiming with the wiimote may get really strange (I think).

The script for you is the following:

Code: Select all

def mouseMovement():
        deltax = filters.delta(wiimote[0].ahrs.yaw)
        deltay = -filters.delta(wiimote[0].ahrs.pitch)
        mouse.deltaX = filters.deadband(deltax, 0.01) * 30
        mouse.deltaY = filters.deadband(deltay, 0.01) * 30

def analogStick():
	if wiimote[0].nunchuck.stick.y > 40:
		keyboard.setPressed(Key.W)
	if wiimote[0].nunchuck.stick.y < -40:
		keyboard.setPressed(Key.S)
	if wiimote[0].nunchuck.stick.x > 40:
		keyboard.setPressed(Key.D)
	if wiimote[0].nunchuck.stick.x < -40:
		keyboard.setPressed(Key.A)
		
def map_wiimote_to_key(wiimote_index, wiimote_button, key):
    # Check the global wiimote object's button state and set the global
    # keyboard object's corresponding key.
    if wiimote[wiimote_index].buttons.button_down(wiimote_button):
        keyboard.setKeyDown(key)
    else:
        keyboard.setKeyUp(key)
        
def map_nunchuck_to_key(wiimote_index, wiimote_button, key):
    # Check the global nunchuck object's button state and set the global
    # keyboard object's corresponding key.
    if wiimote[wiimote_index].nunchuck.buttons.button_down(wiimote_button):
        keyboard.setKeyDown(key)
    else:
        keyboard.setKeyUp(key)
   
def keyboardControl():
    #wiimote
    map_wiimote_to_key(0, WiimoteButtons.DPadUp, Key.NumberPad1)
    map_wiimote_to_key(0, WiimoteButtons.DPadDown, Key.NumberPad2)
    map_wiimote_to_key(0, WiimoteButtons.DPadLeft, Key.NumberPad3)
    map_wiimote_to_key(0, WiimoteButtons.DPadRight, Key.NumberPad4)
    map_wiimote_to_key(0, WiimoteButtons.One, Key.LeftShift)
    map_wiimote_to_key(0, WiimoteButtons.Two, Key.Q)
    map_wiimote_to_key(0, WiimoteButtons.A, Key.R)
    #nunchuck
    map_nunchuck_to_key(0, NunchuckButtons.C, Key.Space)
    map_nunchuck_to_key(0, NunchuckButtons.Z, Key.E)
    
def mouseControl():
    mouse.leftButton = wiimote[0].buttons.button_down(WiimoteButtons.B)

if starting:
    global previous
    previous = False
    wiimote[0].buttons.update += mouseControl
    wiimote[0].motionplus.update += mouseMovement	
    wiimote[0].nunchuck.update += analogStick
    wiimote[0].buttons.update += keyboardControl
    wiimote[0].enable(WiimoteCapabilities.MotionPlus | WiimoteCapabilities.Extension)
Post Reply

Return to “FreePIE”