[SOLVED] weird rotation issue using setH

Return to Scripting Issues

[SOLVED] weird rotation issue using setH

Postby ZetronMan » Mon Apr 16, 2012 4:16 pm

Edit: SOLVED. To others facing this issue, remember that Blender by default with multiple objects will use the center of the workspace as the center, make sure that you move your model to location 0,0,0 and build from there. Then make sure that use ctrl+a to apply loc/rot/scale. :oops:

Hi,

I'm working on a "2D" (made with 3D cubes) platformer in which the player can jump and move left/right. Instead of keyframing the left/right facing of the player, I figured I would just rotate the model 180 degrees, which the code looks something like this:

Code: Select all
    def updatePlayer(self):
        self.dtMove = globalClock.getDt()
        if (self.keymap["left"] != 0):
            # Get the H value to dictate the direction the player faces
            if(self.player.getH() != 180):
                self.player.setH(180)
               
            # Base movement on delta time
            self.player.setX(self.player, self.dtMove * 100)
            # We only want the animation to change at 10fps, anything more is hard to see
            # So we compare the current frame time to the last time frame time was set
            # which is done every time we actually update
            if(float(globalClock.getFrameTime()) - float(self.ft) >= .1):
                # Get the current pose
                frame = self.player.getCurrentFrame('dante_walk')
                # Make sure we're only setting the pose to 2 of it's not 0 or 1
                if (frame == 0 or frame == 1):
                    self.player.pose("dante_walk",2)
                    self.ft = globalClock.getFrameTime()
                elif (frame == 2):
                    self.player.pose('dante_walk',1)
                    self.ft = globalClock.getFrameTime()
                   
        # This is exactly the same as left, but the direction is 0 instead of 180
        # Since movement is relative, make sure to leave the same value for setX()           
        if (self.keymap["right"] != 0):
            if(self.player.getH() != 0):
                self.player.setH(0)
            self.player.setX(self.player, self.dtMove * 100)
            if(float(globalClock.getFrameTime()) - float(self.ft) >= .1):
                frame = self.player.getCurrentFrame('dante_walk')
                if (frame == 0 or frame == 1):
                    self.player.pose("dante_walk",2)
                    self.ft = globalClock.getFrameTime()
                elif (frame == 2):
                    self.player.pose('dante_walk',1)
                    self.ft = globalClock.getFrameTime()


basically, if the getH returns 180, set to 0, if it's 0 set to 180, depending on which key is pressed. However, here are a couple of screen grabs:

this is when I press the 'd' key to move right:
Image
This is when I press the 'a' key to move left:
Image

I'm having a hard time wrapping my brain around where the problem could be as I should just be rotating around the Z-axis for the center of the model, right? Anyone have any idea then why the model would be moving up and down? Perhaps a better method by which to do this?

If it helps, the model and "animation" are all just keyframes taken every frame for all objects, then grouped and exported to .x format (not intending to work with .egg at the moment)

edit to add: rotating in blender by 180 degrees does not seem to show the problem. :?

Thanks!
ZM
Last edited by ZetronMan on Tue Apr 17, 2012 11:08 am, edited 1 time in total.
ZetronMan
 
Posts: 62
Joined: Mon Jan 31, 2011 3:59 pm
Location: Oregon

Postby ZetronMan » Tue Apr 17, 2012 10:26 am

So, I got to thinking about this a bit more, and was wondering how panda decides what the x,y,z value for a model loaded in that's made up of several independent parts. I made my little pixel looking guy by starting blender with the default cube then copying the cube and using the ctrl key to restrict movement to snap to the grid.

I'm wondering if the x,y,z value is based on some part of the group of objects that's closest to the camera or something other method of determination that I am not aware of. I can see how rotating the model 180 degrees could put some other part of the model ever so slightly closer to the camera. Does that help anyone's ability to help me out?
ZetronMan
 
Posts: 62
Joined: Mon Jan 31, 2011 3:59 pm
Location: Oregon


Return to Scripting Issues

Who is online

Users browsing this forum: Thaumaturge and 0 guests