WiiMote Walking

Official forum for open source FreePIE discussion and development.
Post Reply
rizzenwsv
One Eyed Hopeful
Posts: 6
Joined: Thu Mar 26, 2015 5:23 am

WiiMote Walking

Post by rizzenwsv »

Hi guys i stumbled upon freepie after getting my DK2 and love the idea of using wiimotes for movement and such but freepie is daunting, so would anyone have any suggestions on what to do.

i personaly saw this and thought it could work very well
https://forums.oculus.com/viewtopic.php?t=6853
https://www.youtube.com/watch?v=jI266__ ... e=youtu.be

but its glovepie and doesnt work with my TR wiimotes

anyways im noy asking for code or anything im just asking for suggestions for a newbie :P thx guys :D


---UPDATE--

using that video and some scripts i found with a little guess work i was able to make this script
you put the first set of wiimotes in your pockets and use the joystick on the second set to pick a direction, you wont move to actually run in place though

could use a little work but i ran around whiterun in skyrim for about 30 mins with this and it seemed actually not too bad
next up, fine tuning and button mapping.

lemme know what ya guys think

Code: Select all

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 log_acceleration():
	diagnostics.watch(wiimote[0].acceleration.x)
	diagnostics.watch(wiimote[0].acceleration.y)
	diagnostics.watch(wiimote[0].acceleration.z)

	diagnostics.watch(wiimote[1].acceleration.x)
	diagnostics.watch(wiimote[1].acceleration.y)
	diagnostics.watch(wiimote[1].acceleration.z)
	
	if wiimote[0].acceleration.y > 20:
		if wiimote[1].nunchuck.stick.y > 20:
			keyboard.setKeyDown(Key.W)
		else keyboard.setKeyUp(Key.W):
		if wiimote[1].nunchuck.stick.y < -20:
			keyboard.setKeyDown(Key.S)
		else keyboard.setKeyUp(Key.):
		if wiimote[1].nunchuck.stick.x > 20:
			keyboard.setKeyDown(Key.D)
		if wiimote[1].nunchuck.stick.x < -20:
			keyboard.setKeyDown(Key.A)
        
def log_motionplus():
	diagnostics.watch(wiimote[0].ahrs.yaw)
	diagnostics.watch(wiimote[0].ahrs.pitch)
	diagnostics.watch(wiimote[0].ahrs.roll)        

def log_nunchuck():
	diagnostics.watch(wiimote[0].nunchuck.acceleration.x)
	diagnostics.watch(wiimote[0].nunchuck.stick.y)
	diagnostics.watch(wiimote[0].nunchuck.acceleration.y)
	diagnostics.watch(wiimote[0].nunchuck.acceleration.z)
	diagnostics.watch(wiimote[0].nunchuck.buttons.button_down(NunchuckButtons.Z))
	if wiimote[0].nunchuck.acceleration.y > 20:
		if wiimote[1].nunchuck.stick.y > 20:
			keyboard.setPressed(Key.W)
		if wiimote[1].nunchuck.stick.y < -20:
			keyboard.setPressed(Key.S)
		if wiimote[1].nunchuck.stick.x > 20:
			keyboard.setPressed(Key.D)
		if wiimote[1].nunchuck.stick.x < -20:
			keyboard.setPressed(Key.A)

def update():
    # Sideways controls (DPad). Map each of our desired keys.
    map_wiimote_to_key(0, WiimoteButtons.DPadRight, Key.UpArrow)
    map_wiimote_to_key(0, WiimoteButtons.DPadLeft, Key.DownArrow)
    map_wiimote_to_key(0, WiimoteButtons.DPadUp, Key.LeftArrow)
    map_wiimote_to_key(0, WiimoteButtons.DPadDown, Key.RightArrow)
    # 1 button --> Z key
    map_wiimote_to_key(0, WiimoteButtons.One, Key.Z)
    # 2 button --> X key
    map_wiimote_to_key(0, WiimoteButtons.Two, Key.X)
    # - button --> Right shift key
    map_wiimote_to_key(0, WiimoteButtons.Minus, Key.RightShift)
    # + button --> Enter key
    map_wiimote_to_key(0, WiimoteButtons.Plus, Key.Return)

# If we're starting up, then hook up our update function.
if starting:
	# wiimote[0].enable(WiimoteCapabilities.MotionPlus | WiimoteCapabilities.Extension)
	# wiimote[1].enable(WiimoteCapabilities.MotionPlus | WiimoteCapabilities.Extension)

	wiimote[0].buttons.update += update
	wiimote[0].nunchuck.update += log_nunchuck
	wiimote[0].motionplus.update += log_motionplus
	wiimote[0].acceleration.update += log_acceleration

	wiimote[1].buttons.update += update
	wiimote[1].nunchuck.update += log_nunchuck
	wiimote[1].motionplus.update += log_motionplus
	wiimote[1].acceleration.update += log_acceleration
    
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: WiiMote Walking

Post by CyberVillain »

Nice work!
rizzenwsv
One Eyed Hopeful
Posts: 6
Joined: Thu Mar 26, 2015 5:23 am

Re: WiiMote Walking

Post by rizzenwsv »

well somehow I put the wrong script up. but the one I did have that worked didn't have the best movement it seemed to be very jerky so I am working on a better script at the moment.
I'll post an update of that soon
rizzenwsv
One Eyed Hopeful
Posts: 6
Joined: Thu Mar 26, 2015 5:23 am

Re: WiiMote Walking

Post by rizzenwsv »

This is my current script for walking in GTA 5, though it is very much a work in progress atm I am quite happy with it

wiimote+nunchuck 0
use the joystick to select which direction you wish to move, currently its basically wsad and diagonals also have a few buttons mapped and the starts of profile switching
nunchuck in right hand wiimote in left

wiimote 1
place in sock on your calf upside down. wiimote[0].acceleration.y should be around 9-10.

using the joystick while walking in place will allow you to move ingame

Code: Select all

import time

def wiimote_press(wiimote_index, wiimote_button, key):
    if wiimote[wiimote_index].buttons.button_pressed(wiimote_button):
        keyboard.setPressed(key)
        
def wiimote_down(wiimote_index, wiimote_button, key):
    if wiimote[wiimote_index].buttons.button_down(wiimote_button):
        keyboard.setKeyDown(key)
    else:
        keyboard.setKeyUp(key)
        
def chuck_down(chuck_index, chuck_button, key):
	if wiimote[chuck_index].nunchuck.buttons.button_down(chuck_button):
		keyboard.setKeyDown(key)
	else:
		keyboard.setKeyUp(key)

def log_acceleration():

	global mode
	global altfire

	diagnostics.watch(wiimote[0].acceleration.x)
	diagnostics.watch(wiimote[0].acceleration.y)
	diagnostics.watch(wiimote[0].acceleration.z)

	diagnostics.watch(wiimote[1].acceleration.x)
	diagnostics.watch(wiimote[1].acceleration.y)
	diagnostics.watch(wiimote[1].acceleration.z)
	
	
	if mode == 0 and altfire == 0:
		if wiimote[1].acceleration.y > 11 or wiimote[1].acceleration.y < 7:
			if wiimote[0].nunchuck.stick.y > 25 and wiimote[0].nunchuck.stick.x > 25:
				keyboard.setKeyDown(Key.W)
				keyboard.setKeyDown(Key.D)
				time.sleep(.3)
				keyboard.setKeyUp(Key.W)
				keyboard.setKeyUp(Key.D)
			elif wiimote[0].nunchuck.stick.y < -25 and wiimote[0].nunchuck.stick.x > 25:
				keyboard.setKeyDown(Key.S)
				keyboard.setKeyDown(Key.D)
				time.sleep(.3)
				keyboard.setKeyUp(Key.S)
				keyboard.setKeyUp(Key.D)	
			elif wiimote[0].nunchuck.stick.y < -25 and wiimote[0].nunchuck.stick.x < -25:
				keyboard.setKeyDown(Key.S)
				keyboard.setKeyDown(Key.A)
				time.sleep(.3)
				keyboard.setKeyUp(Key.S)
				keyboard.setKeyUp(Key.A)		
			elif wiimote[0].nunchuck.stick.y > 25 and wiimote[0].nunchuck.stick.x < -25:
				keyboard.setKeyDown(Key.W)
				keyboard.setKeyDown(Key.A)
				time.sleep(.3)
				keyboard.setKeyUp(Key.W)
				keyboard.setKeyUp(Key.A)		
			elif wiimote[0].nunchuck.stick.y > 25:
				keyboard.setKeyDown(Key.W)
				time.sleep(.3)
				keyboard.setKeyUp(Key.W)
			elif wiimote[0].nunchuck.stick.x > 25:
				keyboard.setKeyDown(Key.D)
				time.sleep(.3)
				keyboard.setKeyUp(Key.D)			
			elif wiimote[0].nunchuck.stick.y < -25:
				keyboard.setKeyDown(Key.S)
				time.sleep(.3)
				keyboard.setKeyUp(Key.S)
			elif wiimote[0].nunchuck.stick.x < -25:
				keyboard.setKeyDown(Key.A)
				time.sleep(.3)
				keyboard.setKeyUp(Key.A)
		
def log_motionplus():

	global altfire
	global mode
	
	diagnostics.watch(wiimote[0].ahrs.yaw)
	diagnostics.watch(wiimote[0].ahrs.pitch)
	diagnostics.watch(wiimote[0].ahrs.roll)
	diagnostics.watch(wiimote[0].motionplus.yaw_down)
	diagnostics.watch(wiimote[0].motionplus.pitch_left)
	diagnostics.watch(wiimote[0].motionplus.roll_left)	
	
	diagnostics.watch(wiimote[1].ahrs.yaw)
	diagnostics.watch(wiimote[1].ahrs.pitch)
	diagnostics.watch(wiimote[1].ahrs.roll)
	diagnostics.watch(wiimote[1].motionplus.yaw_down)
	diagnostics.watch(wiimote[1].motionplus.pitch_left)
	diagnostics.watch(wiimote[1].motionplus.roll_left)	
	
	if mode == 1:
		if wiimote[0].ahrs.yaw > 210:
			keyboard.setPressed(Key.D)
		if wiimote[0].ahrs.yaw < 190:
			keyboard.setPressed(Key.A)

def log_nunchuck():

	global altfire
	global mode
	
	diagnostics.watch(altfire)
	diagnostics.watch(wiimote[0].nunchuck.acceleration.x)
	diagnostics.watch(wiimote[0].nunchuck.stick.y)
	diagnostics.watch(wiimote[0].nunchuck.acceleration.y)
	diagnostics.watch(wiimote[0].nunchuck.acceleration.z)
	diagnostics.watch(wiimote[0].nunchuck.buttons.button_down(NunchuckButtons.Z))
	
	if mode == 0:
		mouse.leftButton = wiimote[0].nunchuck.buttons.button_down(NunchuckButtons.Z)
	
	if mode == 1:
		chuck_down(0, NunchuckButtons.Z, Key.W)
			
	
	if wiimote[0].nunchuck.buttons.button_down(NunchuckButtons.C):
		altfire = 1
	else:
		altfire = 0

def update():
	
	global altfire
	global mode
	
	diagnostics.watch(mode)
	
	if mode == 0:
		if altfire == 0:
			wiimote_down(0, WiimoteButtons.A, Key.F)
			mouse.rightButton = wiimote[0].buttons.button_down(WiimoteButtons.B)
			wiimote_down(0, WiimoteButtons.Plus, Key.Escape)
			
			wiimote_down(0, WiimoteButtons.Minus, Key.V)
			
		if altfire == 1:
			wiimote_down(0, WiimoteButtons.A, Key.LeftShift)

	if wiimote[0].buttons.button_pressed(WiimoteButtons.One):
		mode = 0
	elif wiimote[0].buttons.button_pressed(WiimoteButtons.Two):
		mode = 1

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

	wiimote[0].enable(WiimoteCapabilities.MotionPlus | WiimoteCapabilities.Extension)
	wiimote[1].enable(WiimoteCapabilities.MotionPlus | WiimoteCapabilities.Extension)
	
	altfire = 0
	mode = 0
	
	wiimote[0].buttons.update += update
	wiimote[0].nunchuck.update += log_nunchuck
	wiimote[0].motionplus.update += log_motionplus
	wiimote[0].acceleration.update += log_acceleration

	wiimote[1].buttons.update += update
	wiimote[1].nunchuck.update += log_nunchuck
	#wiimote[1].motionplus.update += log_motionplus
	wiimote[1].acceleration.update += log_acceleration
    
User avatar
cybereality
3D Angel Eyes (Moderator)
Posts: 11407
Joined: Sat Apr 12, 2008 8:18 pm

Re: WiiMote Walking

Post by cybereality »

Nice.
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: WiiMote Walking

Post by CyberVillain »

Cool, you can add it to the community contributed scripts in the wiki if you want

https://github.com/AndersMalmgren/FreeP ... ed-scripts
rizzenwsv
One Eyed Hopeful
Posts: 6
Joined: Thu Mar 26, 2015 5:23 am

Re: WiiMote Walking

Post by rizzenwsv »

Yeah ill defintely add it to the wiki, i just need to fine tune to walking to make it a bit smoother and then add some comments to the script so ppl know whats going on.
i think ill add some scripts for other games as i make them, skyrim will prob be next.

if anyone out there has some wiimotes and can give this a shot a second opinion of the script would be quite nice.
all in all this is getting better and better for me and i really feel i can get a cheap walking system setup for people to use.
rizzenwsv
One Eyed Hopeful
Posts: 6
Joined: Thu Mar 26, 2015 5:23 am

Re: WiiMote Walking

Post by rizzenwsv »

Quick question: I want to have the mouse button held when I bring the wiimote over my head but I can't seem to find how to do this based on it being triggered by acceleration, any ideas?
Post Reply

Return to “FreePIE”