I wrote a script for an arm aiming animation (FPS & TPS Game) the
script uses the mouse YPosition Value to determine the current
frame of the animation. This system worked well be for I added an FPS camera to the scene
this is because the camera needs the line that returns the mouse Position to 0,0
when this happens the animation’s current frame also returns to zero
causing the animation to act weird.
How do I get around this problem?
Note: I am using Blender 2.68a.
Thanks. Any Help and Solutions will be greatly appreciated.
Here is the file I am using to test and make the script.
To see what I am talking about follow the procedures below
Open the blend file and press P(Play).
(You can use camera view to see things from an FPS angle).
Move the mouse up and down and you should see the thin long part of the cube animate up and down as well
The thin long part of the cube represents the arm that will carry the gun.
the objective is to have the player’s arm aiming in the same vertical direction as the crosshair.(Yes the fps setup is not complete)
Now to view the problem go to the last line of the script and delete the “#” character right at the beginning of the statement and press P
Move the mouse up and down again while looking at the cube animation.
See the difference.
My objective is to have the animation work the same way it did be for the last line of the script was enabled after the line has been enabled.
Thanks.
@adwitandrew
Piece of advice (no offense intended). People are not on these forums every minute of the day. I visit for maybe half-an hour twice a day, and do not have time to answer every question. Nor do I know the answer to every question. On top of that, there is timezone differences. So if people aren’t answering your question straight away, it is nettiquette to wait at least 24 hours before bumping the thread.
About the actual problem:
Trying to sync an animation with a movement is generally hard, as the animation may have things like smoothing applied to it. What is generally done is to parent things together, eg the camera to the armature controlling the animation.
In this case though, the problem is one of absolute vs relative co-ordinates. When you un-comment the last line, the mouse values become instantaneous: the change since the previous position. But the animation is in global/absolute co-ordinates. It looks at where it is relative to the center, rather than relative to where it was last frame.
So to fix it you’ll have to find some way of turning the instantaneous change of mouse into a overall mouse position. You can do this by doing something that sounds fancy, but really isn’t. It’s called Numerical Integration. It’s also known as adding them together.
change from frame 1 to 6 = 0.01 + 0.03 - 0.02 0 0.01 + 0.1 + 0.04
Doing a similar thing here should work, if I understand the problem correctly.
So if you have a game property, and every frame, you add the mouse input to it, then you can feed the property value into the animation code you’ve written.
I’m actually wondering if this is the best way to do it though. Most games move the camera with the arm, in which case you can just scrap the animation stuff and un-comment the drot stuff you had earlier (though you will have problems with global vs local as soon as the player rotates).
I’d recommend picking through some other scripts, namely the mouselook at Tutorialsforblender3D