0

I've got this object player1 and i can't get the scene.add(Obj); line to work as it comes up with an error saying Obj does not exist:

function Player(x, y, z) {
 this.Speed = 0;
 this.AngleAcc = 0;
 this.Angle = 0;
 this.X=x;
 this.Y=y;
 this.Z=z;
 this.MaxSpeed = 100;

 var PlayerMateririal = new THREE.MeshLambertMaterial({ color: 0x00ff80, overdraw: 0.5 });
 this.Obj = new THREE.Mesh(new THREE.BoxGeometry(50, 90, 60), PlayerMateririal);
 scene.add(Obj);
 Obj.position.set(x, y, z);
}

thanks i'm using Three.js and want to set the Obj position in other locations hence why i'm setting it up as a property.

2
  • You left off this - should be this.Obj.position.set(...) Commented Dec 25, 2014 at 15:29
  • 2
    Obj is not a variable. You defined it as a property of this, then you should use this.Obj or simply try var Obj = this.Obj = new THREE..... Commented Dec 25, 2014 at 15:30

1 Answer 1

1

Use this keyword

scene.add(this.Obj);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.