# Player's movements and OimoJS

## Recommended Posts

Hello guys !

So, I'm trying to make an FPS. My player is a box, and I wanted to enable Oimo physics with it.

But here come the problems :
- OimoJS only have box, sphere and plane impostor. I would have prefered a Cylinder or a Capsule one in order to represent my player accurately.
- I don't know how to "fix" the orientation of my mesh. I mean, I'd like my boxmesh (representing the player) to always be parallel to the horizontal plane. (Which means it can only rotate around the Y axis).

- I'd like my player to be able to climb stairs while still being vertical. (So it doesn't mess with collisions) But I don't know how Oimo would react, as I am not able to "fix" its orientation.

Making it rotate around the Y axis was quite difficult, as I never used quaternion before, but I managed to make it work with a really bad function made by myself (

{    function quatPquat(q, w, x, y, z) {        var tw = q.s * w - q.x * x - q.y * y - q.z * z;        var tx = q.s * x + q.x * w - q.y * z + q.z * y;        var ty = q.s * y + q.x * z + q.y * w - q.z * x;        var tz = q.s * z - q.x * y + q.y * x + q.z * w;        q.s = tw;        q.x = tx;        q.y = ty;        q.z = tz;    } // q *= (w, x, y, z)    function quatYRotate(q, v) {        quatPquat(q, Math.cos(v), 0, Math.sin(v), 0);    }} // Quaternion stuff

)

Any help would be appreciated, thanks !

##### Share on other sites

I'm pretty sure Temechon can help

##### Share on other sites

Hey Testouille !

- OimoJS only have box, sphere and plane impostor. I would have prefered a Cylinder or a Capsule one in order to represent my player accurately.

Indeed, there is no cylinder ot capsule impostor.

- I don't know how to "fix" the orientation of my mesh. I mean, I'd like my boxmesh (representing the player) to always be parallel to the horizontal plane. (Which means it can only rotate around the Y axis).

This is a question someone else asked on the forum, and I was not able to answer correctly. The only thing I know is you can set the angular speed of your mesh like this:

var body = mesh.setPhysicsState(...);var angularSpeed = body.body.angularVelocity;angularSpeed.x = angularSpeed.z = 0;

- I'd like my player to be able to climb stairs while still being vertical. (So it doesn't mess with collisions) But I don't know how Oimo would react, as I am not able to "fix" its orientation.

I have no idea how to do this :/

##### Share on other sites

Generally for stairs, a ramp is used transparently, what helps has to make climb the character.

##### Share on other sites

Teme' : I will try then, or dig in Oimo ^^

I forgot to tell you the other problem :
I want to "go forward", the problem is, when Oimo physics are enabled, I can't use "this.mesh.rotation" to get the current mesh orientation, and this.registeredmesh.body.body.getRotation() gives me rubish. So, I don't know how I can go forward.

Do you have any idea ?

##### Share on other sites

I don't really understand what is the oimo problem as I don't know anything about it, but to set a mesh parallel to an horizontal plane without knowing how to rotate it, you could use RotationFromAxis(axis1, axis2, axis3)

don't know if it suits to your problem however

##### Share on other sites

Jerome, when you're using a physics engine, you cannot control directly the mesh orientation. Everything is handled by the physics body. So RotationFromAxis won't have any effect here.

##### Share on other sites

ok...

aarg... still so many things to learn

##### Share on other sites

Teme' : What about the other problem ?

##### Share on other sites

Ho sorry I didn't read it

I use something like this directly by updating the Oimo body.

this.getScene().registerBeforeRender(function() {   _this.move();   if (_this.position.y < -10) {      _this.game.reset();   }});Player.prototype.move = function() {  if (this.directions[0] != 0) {    this._moveTo(-1);  }  if (this.directions[1] != 0) {    this._moveTo(1);  }  if (this.rotations[0]  != 0) {    this._rotateTo(0.05);  }  if (this.rotations[1]  != 0) {    this._rotateTo(-0.05);  }};Player.prototype._moveTo = function(s) {  this.computeWorldMatrix();  var v = new BABYLON.Vector3(0,0,s);  var m = this.getWorldMatrix();  var v2 = BABYLON.Vector3.TransformCoordinates(v, m);  v2.subtractInPlace(this.position);  v2.scaleInPlace(0.5);  this.applyImpulse(v2, this.position);};Player.prototype._rotateTo = function(s) {  // get mesh quaternion  var mq = this.rotationQuaternion;  // create quaternion to add  var q = BABYLON.Quaternion.RotationYawPitchRoll(s, 0, 0);  this.rotationQuaternion = q.multiply(mq);  this.body.body.setQuaternion(this.rotationQuaternion);  this.body.body.sleeping = false;};

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.