Answers is deprecated.

Please use Forum to participate in community by asking and answering questions!

I am using raycastFirst to get the point where I click on the model.

It works well when the model is loaded. However, when I rotate(or translate) my model, raycast return wrong position.

Here is my code snippets:

// for the model
pc.script.create('modelPhysic', app => {
    return class {
        constructor(entity) {
            this.entity = entity;
            this.collisionAsset = app.assets.get(9999);
        }
        initinalize() {
            this.entity.addComponent('rigidbody');
            this.entity.addComponent('collision', {
                type: 'mesh',
                model: this.collisionAsset.resource
            });
        }
    }
});

// for camera
pc.script.create('picker', app => {
    return class {
        onSelect(e) {
            var from = this.entity.position;
            var to = this.entity.camera.screenToWorld(e.x, e.y, this.entity.camera.farClip);
            var result = this.app.systems.rigidbody.raycastFirst(from, to);
            console.log('result: ', result);
        }
    }
})

I suppose that the collision object do not rotate/translate with the model ? Can anyone help me ?

asked 09 Feb, 11:14

scarlex's gravatar image

scarlex
0224
accept rate: 100%

edited 09 Feb, 11:18


I solved this problem by using

this.entity.rigidbody.teleport(
    this.entity.getPosition(),
    this.entity.getLocalEulerAngles()
);

after the model rotate / translate;

link

answered 10 Feb, 03:00

scarlex's gravatar image

scarlex
0224
accept rate: 100%

edited 27 Feb, 03:10

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×13

Asked: 09 Feb, 11:14

Seen: 422 times

Last updated: 27 Feb, 03:10

about | privacy | support | contact

playcanvas