Object detects touch stopped without me stopping the touch

I am working on a drag and drop system. Right now when I use the preview and click on the object it goes to the center of the screen as it should, and then the dropped/idle calls and the object drops to the ground again. Any insights in what the issue can be?

// This is a component file. You can use this file to define a custom component for your project.
// This component will appear as a custom component in the editor.

import * as ecs from '@8thwall/ecs'  // This is how you access the ecs library.

ecs.registerComponent({
  name: 'Draggable',
  schema: {
    camera: ecs.eid,
    distanceToCamera: ecs.f32,
    followSpeed: ecs.f32,
  },
  schemaDefaults: {
    distanceToCamera: 3,
    followSpeed: 50,
  },
  data: {
    touchPositionX: ecs.f32,
    touchPositionY: ecs.f32,
  },
  add: (world, component) => {
    // Init data
    const {eid, dataAttribute} = component

    // Set to middle screen
    component.data.touchPositionX = 0.5
    component.data.touchPositionY = 0.5

    // Get mass data for later caching
  },
  stateMachine: ({world, eid, schemaAttribute}) => {
    ecs.defineState('idle')
      .initial()
      .onEnter(() => {
        ecs.Collider.set(world, eid, {mass: 1})
        console.log('Idle')
      })
      .onEvent(ecs.input.SCREEN_TOUCH_START, 'following', {
        target: eid,
      })
    ecs.defineState('following')
      .onEnter(() => {
        ecs.Collider.set(world, eid, {mass: 0})
        console.log('dragging')
      })
      .onTick(() => {
        const schema = schemaAttribute.cursor(eid)
        const {camera, distanceToCamera, followSpeed} = schema

        // Get the camera's position and rotation
        const cameraPosition = ecs.Position.get(world, camera)
        const cameraRotation = ecs.Quaternion.get(world, camera)

        // Get screen size
        // Calculate relative position of object

        // Calculate the forward vector from the camera's rotation
        const forward = {
          x: 2 * (cameraRotation.x * cameraRotation.z + cameraRotation.w * cameraRotation.y),
          y: 2 * (cameraRotation.y * cameraRotation.z - cameraRotation.w * cameraRotation.x),
          z: 1 - 2 * (cameraRotation.x * cameraRotation.x + cameraRotation.y * cameraRotation.y),
        }

        // Scale the forward vector by the desired distance
        const forwardOffset = {
          x: forward.x * distanceToCamera,
          y: forward.y * distanceToCamera,
          z: forward.z * distanceToCamera,
        }

        // Calculate the new position in front of the camera
        const newPosition = {
          x: cameraPosition.x + forwardOffset.x,
          y: cameraPosition.y + forwardOffset.y,
          z: cameraPosition.z + forwardOffset.z,
        }

        // Smoothly interpolate towards the target position (if followSpeed is used)
        const currentPosition = ecs.Position.get(world, eid)
        const smoothedPosition = {
          x: currentPosition.x + (newPosition.x - currentPosition.x) * (followSpeed / 100),
          y: currentPosition.y + (newPosition.y - currentPosition.y) * (followSpeed / 100),
          z: currentPosition.z + (newPosition.z - currentPosition.z) * (followSpeed / 100),
        }

        // Set the new position for the object
        ecs.Position.set(world, eid, {x: smoothedPosition.x, y: smoothedPosition.y, z: smoothedPosition.z})
      })
      // .listen(eid, ecs.input.SCREEN_TOUCH_MOVE, handleFollow)
      .onEvent(ecs.input.SCREEN_TOUCH_END, 'idle', {
        target: eid,
      })
  },
})

Might be easier to use world.setPosition.

Same result. Works in demo project, but not in my game.
Here is a video of what happens:

Performance also is low, could that cause issues?
Code is in the sample project: Studio: Drag and Drop | Dunk Technologies | 8th Wall

That’s interesting. Does the entity have physics enabled? If you remove the physics from the object, does the issue still occur? If not, you might want to consider disabling the physics component while the object is being dragged, or setting its gravity to 0.

If I make it static the issue is still there. Removing the collider same issue (didn’t know the touched works without collider, neat). Then it just floats in the air and still doesn’t follow the camera.
The event idle also calls immediately

Fixed by changing project camera to 3D only instead of world.
The touch end event gets called instantly in the VPS location simulator

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.