1

I'm trying to make a flight simulator for a project, and I'm trying to place a cockpit image in front of my camera, which is being controlled with FirstPersonControls, I've tried many things but I can't make it work.

here's what I got so far: The cockpit image should be in front of the camera

I got this running in a: Codepen Project

This is where I'm trying to place the image.

    function onTextureLoad(texture) {
    console.log(texture);
    var geometry = new THREE.PlaneGeometry(2, 2, 0);
    var material = new THREE.MeshBasicMaterial({
     map: texture, transparent: true, opacity: 1 
    });

    var geometryco = new THREE.PlaneGeometry(100,100,100,100);
    var cockpit = new THREE.Mesh(geometryco, material);
    cockpit.position.set(0,20,0);

    scene.add(cockpit);

    render();
  }

Any help would be appreciated

1
  • @Rabbid76 How would I do that ? Commented May 21, 2018 at 7:47

2 Answers 2

2

Make it a child of the camera so that they move together.

camera.add( cockpit )
scene.add( camera )
Sign up to request clarification or add additional context in comments.

2 Comments

Where would I place that? , inside the function? , sorry I'm really new at this, I tried that but it doesn't show the image
Instead of scene.add( cockpit )
2

Another option is to put the cockpit in the img tag, which is in front of the renderer's canvas:

html:

<img src="https://i.imgur.com/VfF0ada.png" style="position:absolute; width:100%; height:100%"/>

js:

renderer = new THREE.WebGLRenderer({});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

https://codepen.io/prisoner849/pen/qYgKvz?editors=0010

2 Comments

Wait that's css,I just realized.. I need it in three js
@RodolfoR :) It's up to you. If you want to make it more complicated, so be it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.