chandlerprall / Physijs

Physics plugin for Three.js
MIT License
2.75k stars 454 forks source link

threejs firstPersonControls #252

Open bachy opened 8 years ago

bachy commented 8 years ago

Hello, i now there is an old issue about that : https://github.com/chandlerprall/Physijs/issues/86 but there is no answers and i can't find any answer on web. when i try to add a physijs mesh on threejs firstpersoncontrol, the mesh don't want to move rotation is ok, but x,y,z movement is not working :( is this possible or a will have to code my own control part ? :(

Luxilia commented 8 years ago

The only way I've found to implement something like firstpersoncontrols in physijs is by never rotating the character mesh, and instead rotating the camera, and giving the character mesh a velocity based on the direction the camera is looking.

ghost commented 8 years ago

@bachy are you using the physijs mesh .__dirtyPosition and .__dirtyRotation flags before updating scene? Using the flags means overwritting the position / rotation of meshes while still keeping collision detection and response.

kampfhamster94 commented 8 years ago

I have a similar issue. I've created a physijs capsule as the player with a camera attached as a child. Rotating the camera is no problem but I can't get my movement working.

In an earlier build without physijs I could move the camera by the "translateX/Y/Z" commands, which worked fine, because it targets the local coordinates of the camera.

But "translateX/Y/Z" doesn't work for physijs objects so i tried "setLinearVelocity", but this targets the global axis. My player (with attached camera) can walk, but when i turn around my "forward movement" is not forward anymore (if you understand, what I want to say^^).

@Luxilia You recommended 'giving the character mesh a velocity based on the direction the camera is looking' do you or anybody else have a working solution for that?

Luxilia commented 8 years ago

Implemented something like this in this project. https://github.com/Akimoto873/WebGL-Platformer/blob/master/Platform/WebContent/js/charController.js

kampfhamster94 commented 8 years ago

Thanks for the quick response. I tried to implement it and it seems to work per se but not for every angle. When I turn to the right everything works fine but on the lefthand side the movement turns by 90°. Which means before I had W=Forward,A=Left,S=Back,D=Right. On the left I suddenly have W=Right,A=Forward,S=Left,D=Back.

Luxilia commented 8 years ago

That means you missed a part somewhere in my code ^^ Quite a long time since I did this now, but I remember something about changing the priority of the axis'. camera.eulerOrder = "YXZ" I remember I struggled a bit with the problem you mentioned, before I figured out how to get it right ^^

2016-06-01 15:23 GMT+02:00 kampfhamster94 notifications@github.com:

Thanks for the quick response. I tried to implement it and it seems to work per se but not for every angle. When I turn to the right everything works fine but on the lefthand side the movement turns by 90°. Which means before I had W=Forward,A=Left,S=Back,D=Right. On the left I suddenly have W=Right,A=Forward,S=Left,D=Back.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/chandlerprall/Physijs/issues/252#issuecomment-222990511, or mute the thread https://github.com/notifications/unsubscribe/APDk_8oS-PqqEdy4v-4FP81T5BNKWdDRks5qHYfOgaJpZM4GWjO2 .

kampfhamster94 commented 8 years ago

Yey, changing the euler order helped and not it works fine.

Thanks a lot ;D