alright… i just cant figure this one out… i have a full rigged character and im all set and ready to start with the mouse look script… how can i set it up so when i look left and right the whole character turns and when i look up and down only the top half/arms move up and down? (and the legs stay where they are)
this is the script im using if thats any help
######################################################
#
# MouseLook.py Blender 2.46
#
# Tutorial for using MouseLook.py can be found at
#
# www.tutorialsforblender3D.com
#
######################################################
# import Rasterizer
import Rasterizer
# get controller
controller = GameLogic.getCurrentController()
# get the object this script is attached to
player = controller.getOwner()
# Get sensor named Mouse
mouse = controller.getSensor("Mouse")
# Get the actuators
lookLeftRight = controller.getActuator("LookLeftRight")
lookUpDown = controller.getActuator("LookUpDown")
# get width and height of game window
width = Rasterizer.getWindowWidth()
height = Rasterizer.getWindowHeight()
# define mouse movement function
def mouseMove():
# distance moved from screen center
x = width/2 - mouse.getXPosition()
y = height/2 - mouse.getYPosition()
# intialize mouse so it doesn't jerk first time
if hasattr(player, 'mouseInit') == False:
x = 0
y = 0
# bug in Add Property
# can't use True. Have to use 1
player.mouseInit = 1
# return mouse movement
return (x, y)
# get mouse movement from function
move = mouseMove()
# set mouse sensitivity
sensitivity = 0.0005
# Amount, direction and sensitivity
leftRight = move[0] * sensitivity
upDown = move[1] * sensitivity
# Smooth movement
player.oldLeftRight = (player.oldLeftRight*0.5 + leftRight*0.1)
player.oldUpDown = (player.oldUpDown*0.5 + upDown*0.1)
upDown = player.oldUpDown
leftRight = player.oldLeftRight
# set the values
lookLeftRight.setDRot( 0.0, 0.0, leftRight, False)
lookUpDown.setDRot( upDown, 0.0, 0.0, True)
# Use them
GameLogic.addActiveActuator(lookLeftRight, True)
GameLogic.addActiveActuator(lookUpDown, True)
# Center mouse in game window
Rasterizer.setMousePosition(width/2, height/2)
Um, I think the simpler way to do this is splitting the character in two parts…
I mean, you use 2 Meshes, one for the lower body and the other for the upper, same for the armature ( and parent the two half together of course )
If someone has a better/simpler solution please share, I would like to learn how to do it too, since splitting a character doesn’t seem very “professional” to me ^_^"
P.S.: Yes, there should be a way to rotate bones in Python but i never tried nor seen it unfortunately :0) It’ld be a very nice technique to use tough :b
yeah… i was thinking in school today… that maybe i should just split the ameture and not the mesh but the only issue with that is… when a person looks up and down while holding a gun… he dosent just bend at the back… his arms and head move the most… so im gunna keep thinking but if anyone has any other ideas plz let me know.
Um, I done some research too, but unfortunately I found only bad news:
Seems like the only way to actually manipulate bones in Python is using Blender.Armature. But, the Blender module its not for realtime use, its In-Blender only ( for example moving bones is like selecting a bone and rotating with R, it only affects Blender not the game engine )
I could be wrong tough, I havn’t done a very approfondite research, I just googled so…
But… I have a little present for you, an example of a simple character with a Resident Evil 4 Style Camera ( omg im becoming a pro! :eek: xd ) - It’s using your script ( wich is quite obsolete btw, it uses old code but this doesn’t matter now ), there are 2 meshes ( made out of cubes, i suck at modelling ) and 2 armatures parented to each other so that the lower body moves everything, but it just looks around, no movement. Very basic but this should illustrate the point quite well…