How can I create a if statement to send the camera (player) to the sky once the camera is on a certain coordinate?

I was working on a little test and I was trying to see if I can make if statements because I’m not really good with conditions. I made a condition and it didn’t work. In fact, the part of the condition that was supposed to be executed was executed before the requirements were met.
Here is my test

The specific piece of code is here.

      if (camera.position.x = 5,  camera.position.y = -10,
          camera.position.z = -4) {
          camera.position.y = 4


When using if statements,
== means s condition to checked to see if equal
= means set the variable to the value
there is a third type === which you don’t need to worry about for now, but good to know it exists.

So in your case this:
if (camera.position.x = 5, camera.position.y = -10,
camera.position.z = -4) {

is actually setting: x to 5, y to -10 and z to -4. Not checking if they are at that point.

Also, using comas in if statements is bad form, you should be using && (and), || (or), or &| (and or) to link statements together.

So to re-write:

if (camera.position.x == 5 && camera.position.y == -10 && camera.position.z == -4) {
          camera.position.y = 4; // then move the camera's y cord to + 4

That should get you to where you need to be.


Thank you for the response, but the code you sent me didn’t work. I walk on the brick and nothing changes.