Physijs icon indicating copy to clipboard operation
Physijs copied to clipboard

Rotation issue

Open drtobal opened this issue 10 years ago • 6 comments

Hello,

I am working with this library for a short time, and i have a issue that is killing me.

I have 2 cubes, one with phisy.js and another with three.js, and i have a function for rotate them when you press the A, S, D, or W key depending on the rotation of the camera, my code is like this:

        var v = new THREE.Vector3(0, 0, 0);
        if (keys.forward === 1)
            v.x = -1;
        if (keys.right === 1)
            v.z = 1;
        if (keys.backward === 1)
            v.x = 1;
        if (keys.left === 1)
            v.z = -1;

        //get the searched angle
        var angle = camera.rotation.y + Math.atan2(v.x, v.z);
        var rot = normalMesh.rotation.y;
        var diff = angle - rot;

        if (Math.abs(diff) > Math.PI) {
            //find the shortest way to rotate
            if (diff > 0)
                rot += 2 * Math.PI;
            else
                rot -= 2 * Math.PI;
            diff = angle - rot;
        }
        //get the /2 for a smooth rotation, i really need this
        if (diff !== 0)
            rot += diff / 2;
        normalMesh.rotation.set(0, rot, 0);

on the three.js cube works fine, but on the physi.js cube i doesn't work.

I am created a demo for this (i can´t create it on jsfiddle because the web worker)

http://demo.cristobaldiaz.cl/test/

also i left the source code on a zip file ---> http://demo.cristobaldiaz.cl/test/issue.zip

you can check the movement function on http://demo.cristobaldiaz.cl/test/src/app.js line 95

I would appreciate any help.

thanks in advance.

drtobal avatar Dec 26 '14 06:12 drtobal

NAVER - http://www.naver.com/

[email protected] 님께 보내신 메일 <[Physijs] Rotation issue (#223)> 이 다음과 같은 이유로 전송 실패했습니다.


받는 사람이 회원님의 메일을 수신차단 하였습니다.


jihoonbyun avatar Dec 26 '14 06:12 jihoonbyun

Physijs objects have their position & rotation set every frame based on the physics simulation. To override these values manually you will need to set mesh.__dirtyPosition = true or mesh.__dirtyRotation = true for Physijs to pick up the change.

chandlerprall avatar Dec 26 '14 22:12 chandlerprall

NAVER - http://www.naver.com/

[email protected] 님께 보내신 메일 <Re: [Physijs] Rotation issue (#223)> 이 다음과 같은 이유로 전송 실패했습니다.


받는 사람이 회원님의 메일을 수신차단 하였습니다.


jihoonbyun avatar Dec 26 '14 22:12 jihoonbyun

yes, I know, atually it has that

me.physiMesh.__dirtyPosition = true;
me.physiMesh.__dirtyRotation = true;

after the movement and the rotation

drtobal avatar Dec 27 '14 17:12 drtobal

@drtobal are they set before the movement and rotation? This is required.

mhmhartman avatar Dec 29 '14 16:12 mhmhartman

I had the same problem. The _dirty flag is not executed so fast and therefore the rotation value is not updated with the manually given value but it takes the simulation rotation value. I solved it by making the Physijs.Scene a liitle more slower, i.e. scene = new Physijs.Scene({ reportsize: 50, fixedTimeStep: 1 / 20 }); instead of 1/60

jimver04 avatar Jun 01 '16 12:06 jimver04