Aiming animation problem

Hi I Hope you are having a good day.

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.

What is the arm is supposed to aim to?

Blend or diagrams or more explanation would be great.

Maybe redo the animation to fit the camera’s needs?

Here is the file I am using to test and make the script.

To see what I am talking about follow the procedures below

  1. Open the blend file and press P(Play).
    (You can use camera view to see things from an FPS angle).
  2. 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)
  3. 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
  4. 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.

Attachments

Gun Aim Animation.zip (229 KB)

someone.
@ sedfgeoff I have loaded the blend file

Some body anybody please come to my recue I do not have any more tricks up my sleeve on how to solve this problem I hope someone else does

Thanks. Any Help and Solutions will be greatly appreciated

@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.

So if you have a bunch of small changes:


frame 1 = 0.01
frame 2 = 0.04
frame 3 = -0.02
frame 4 = -0.01
frame 5 = 0.1
frame 6 = 0.04

You can find the overall change by summing them:


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

@sdfgeoff
Thanks for the Help off to try it out.
Apologies I did not mean to bump the thread or ofend anyone. Thanks for the advice as well

Problem solved.

Thanks for the help everyone I really appreciate it.