How would i edit the if statement to allow a ram reaches a certain position the wall moves back a position?

Hey, i have an if statement below i have a moving ram (using a slider) that when it reaches
position -100 a wall should move to position 0 or even better the wall should be destroyed.

Only the ram should be controllable how would i edit the below code and where would i place it as I’m still a beginner to three.js:

Any help would be appreciated to find a fix

function pushBack() {
                if (ramGroup.position.x > -100) {
                            wall.position.x = 0;

Hello jamster1992,

It is difficult to understand what you are trying to achieve with only a small piece of code, but…

from I see in the code snippet, if your slider range from 0 to -100, the conditional statement can’t never be true. You need to add an “=” after the “>” sign to make it a plausible condition.

1 Like

in short when my battering ram reachs -100 on the x axis,

i want the wall to move to postion 0 on the x axis just by moving the ram

in my controls is this -
this.MoveForward = 0;

in my gui is this code -
guiRam.add(controls, ‘MoveForward’, -100, 100);

in the render function is this -
ram.position.set(controls.MoveForward, controls.positionY, controls.positionZ);

ok, then make sure to use

if the previous doesn’t work, use this

if (parseInt(ramGroup.position.x) >= -100) {


if (parseInt(ramGroup.position.x) === -100) {

also make sure to include the pushback() function in the update() loop

1 Like

thanks would the if statement go in the controls or gui?

I will put it in your controls loop, because it is pertinent to controls from what I see. but, you are certainly going to have more cases and the best would be to create a separate/independent app control function/class that will check for the different states, i.e.:

var checkappstate=function(){




and call the “checkappstate()” in the main update loop before the control.update() call.

Either ways, it will work from a coding stand point, you have to see what best suits the app flow.

1 Like

hey thanks its all working apart from one small thing

the ramparts are in a loop and it only pushes the last rampart instead of all five is their anyway to fix this?

Just check how you add your rampart objects to the group (ramGroup). Are you creating an unique object for each wall element before adding them?

You may just be adding the same object to the group. Use the object3D.clone() function call to create distinctive objects. Again without the code in front, it is just a wild guess…

1 Like

im using a for loop to duplicate the same object five times

for ( var i = 0; i < 5; i++ ) {


This sample code is not really helping out…

Just make sure to not add the same object or use the merge geometry function to create one single object instead of a group.