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

105
Views
Raycast threejs touch event not working using mouse event

I’ve been working on threejs mouse raycast with fabricjs, and it is working now here but the problem is the object didn’t move if i was using smartphone which is using touch. Should i create another event listener for touch event? or should it be working just fine using mouse event?

here's how i can move the object

  if (e.target !== this.upperCanvasEl) {
    var positionOnScene = getPositionOnScene(container, e);
    pointer.x = positionOnScene.x;
    pointer.y = positionOnScene.y;
  }

and here's getPositionOnScene function

 function getPositionOnScene(sceneContainer, evt) {
    var array = getMousePosition(container, evt.clientX, evt.clientY);
    onClickPosition.fromArray(array);
    var intersects = getIntersects(onClickPosition, scene.children);
    if (intersects.length > 0 && intersects[0].uv) {
      var uv = intersects[0].uv;
      intersects[0].object.material.map.transformUv(uv);
      return {
        x: getRealPosition('x', uv.x),
        y: getRealPosition('y', uv.y)
      }
    }
    return null
  }

can anyone help me? any thought would be really helpful

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

0

There is 2 reasons.

1:

You return null in the `getPositionOnScene` function.

2:

Touch is not the same as a mouse event.

You will have to do `document.addEventListener("mousedown", callback)`
so it supports mouse events too.
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!