Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
FPS Weapon Bob

Registered User
2023-11-15 12:58:03

Hi, Guys

I am new to the forums, but not that new to game making, i started a FPS beta project years ago with game maker and never finished

Here is the link if you guys want to check it out:

Now my question is, i am using Coppercube, currently using a 2d overlay with an image which i animate(change texture) at certain intervals while walking to simulate the weapon moving.

Now if i want to use an actual 3d object for the weapon, how can i make it move or bob around, it's a static mesh, not animated.

I was thinking of using the change position of 3d object every few seconds with some variables so it looks like the weapon is moving about as long as you are moving with the w key pressed.

Is that the right approach?

2023-11-15 13:27:34

You can add a transparent animated mesh and attach static gun as a child to that transparent mesh, and now make that animated mesh a children of the FPS camera, and there you go, you will have a real bobbing effect for your gun, it also depend on the animation of your main character.

Registered User
2023-11-15 14:22:02

Thanks, i will give it a try and let you know, sounds like a good plan

2023-11-15 14:48:18

welcome @joecoetzee

as another approach you could also make two invisible copies of your weapon (or simply use cubes or empties) with slightly changed positions

have all three meshes parented to the FPS camera

and then let your visible weapon mesh loop animate between the positions of the both auxiliary meshes every defined seconds with this CopperCube Transform To Target action:



Registered User
2023-11-15 15:12:38

Thanks for the welcome!

Your approach is also very interesting, i will have a look tonight after work - thank you

Registered User
2023-11-15 21:51:47

Or you can achieve the same result by coding a simple behavior.
// The following embedded xml is for the editor and describes how the behavior can be edited:
// Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action
<behavior jsname="behavior_WWoble" description="Weapon wobble demo">
<property name="gunNode" type="scenenode" default="" />

// define constants
const KEY_W = 87;
const KEY_S = 83;
const KEY_A = 65;
const KEY_D = 68;

var behavior_WWoble = function () {
this.lastTime = null;
this.curWobbleDelta = 0;
this.lerpIndex = 0.3;

// TODO: do the same for arrow keys
this.movementKeysStates = [false, false, false, false];

behavior_WWoble.prototype.onAnimate = function (node, timeMs) {
if (!this.lastTime) {
this.lastTime = timeMs;
// get initial position on the first frame
this.gunInitPos = ccbGetSceneNodeProperty(this.gunNode, 'Position');
return false;

var delta = timeMs - this.lastTime;
this.lastTime = timeMs;
if (delta > 200) delta = 200;

// increment curWobbleDelta every frame
// reset it if it's greater than 2 * PI
// it's used to offset gun position relative to the initial position
this.curWobbleDelta += delta * 0.01;
if (this.curWobbleDelta > 2 * Math.PI) this.curWobbleDelta -= 2 * Math.PI;

// get current gun position
const gunPos = ccbGetSceneNodeProperty(this.gunNode, 'Position');
// yOffset is current gun offset for this frame
let yOffset = 0;

// check if any of moving keys are pressed
if (this.movementKeysStates.some(function (key) { return key; })) {
// if currently moving - calculate offset
yOffset = Math.sin(this.curWobbleDelta) * 0.2;
} else {
// if not moving offset should be 0, i.e initial position
// curWobbleDelta is reset to 0, since it's required to move from 0 position
// in case player stops
this.curWobbleDelta = 0;

// set gun position considering the calculated offset
// lerp function (linear interpolation) with coefficient lerpIndex
// is used in order to make it change smooth if value change by a big number
// for example if player stops
lerp(gunPos.y, this.gunInitPos.y + yOffset, this.lerpIndex),

return true;

// update movement keys states based on user input
behavior_WWoble.prototype.onKeyEvent = function (key, pressed) {
if (key === KEY_W) this.movementKeysStates[0] = pressed;
if (key === KEY_A) this.movementKeysStates[1] = pressed;
if (key === KEY_S) this.movementKeysStates[2] = pressed;
if (key === KEY_D) this.movementKeysStates[3] = pressed;

function lerp(prev, next, delta) {
return prev + delta * (next - prev);


2023-11-16 00:55:30

And people says, community is rude with newbies, 3 different solution to one small thing. What else you expect from a good community?

Registered User
2023-11-16 06:07:46

Thanks guys!! All suggestions work great!!

One step closer to completing the weapons.

Registered User
2023-11-16 13:52:32

Hi joecoetzee, welcome to the forum!

You can to do this with "follow a path"

You atach the "follow a path" in the player and this way you can balance the weapon while you walk!

Registered User
2023-11-19 18:44:40

Hey guys

I tried the methods, and they seem to work great, you can check it below, i made a small demo

Create reply:

Posted by: (you are not logged in)

Enter the missing letter in: "Internati?nal" (you are not logged in)




Possible Codes

Feature Code
Link [url] [/url]
Bold [b]bold text[/b]
Image [img][/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]



Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact