Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
I get error when I type conditions in JavaScript

I'm newbie with JavaScript and I tryed to store the Vector position and whith two buttons (forward and backward) to move the Camera to that specific position. Also I tried to use 'gsap' to have soft movements but the code don't work.

//Coordinates
let positionIndex = 0;
const positions = [
    {
        x: -0.05,
        y: 0.6,
        z: -0.17
    },

    {
        x: -2,
        y: 1,
        z: 1
    },

    {
        x: 0.3,
        y: 0.6,
        z: -0.6
    }
]

//on buttonforward clicked
var element = document.querySelector(".button-1");
element.onclick = function MoveUp(){

if(positionIndex) == 3
{
    positionIndex = 0;
}
else
{
    positionIndex += 1;
}}

camera.position.x = positions[positionIndex].x
camera.position.y = positions[positionIndex].y
camera.position.z = positions[positionIndex].z


//on buttonbackwards clicked
var element = document.querySelector(".button-2");
element.onclick = function MoveDown(){

if(positionIndex) == 0
{
    positionIndex = 3;
} 
else 
{
    positionIndex -= 1;
}}
camera.position.x = positions[positionIndex].x
camera.position.y = positions[positionIndex].y
camera.position.z = positions[positionIndex].z

Someone can give me advice?

Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

when you set positionIndex to 3 you will get undefined. Perhaps it would be better to use positions.length - 1

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!