Need help coding the movement for the player's weapon

I would like to use the “apply force” or the “apply torque” codes to get the player’s weapon to move around. But everytime i create the code, something goes wrong. Can anyone give me an example code that i can use to get the player’s weapon to swing in a downwards motion when the space bar is pressed and swing back up to its normal position when the space bar is released. Please help.

I wouldn’t use physics to achieve that kind of animation. I would simply perform an interpolation from a start position/rotation to an end position/rotation and back again.

How’s this:

Here’s the project:

https://playcanvas.com/project/367986

thanks, but how can I make it to where the movement is much faster? I can get him to swing the weapon, but very slowly.

I’ve added another script attribute to allow you to set the duration of the animation.