Lock Z axis

Hi.



I’m making a 3D game with moving along X and Y axis and not Z. So it is possible to lock this Z axis? I’m using Bullet.



Regards

You mean constraining the physics behavior on X & Y axis only?



Once I asked the same question and @normen said native bullet can do that. Now we have it. So, the answer is ‘yes’.

@iamcreasy, thanks for reply. So I can do it. My next question is: how? :slight_smile:

Creasy’s conclusion isn’t quite right, you can only lock the rotation completely.

@normen translation can’t be constrained? :frowning:

Lol, constraining translation and rotation is called “kinematic mode” :wink:

1 Like

Yeah, but i don’t want to lock translation and rotation, but only translation in Z axis… :wink:

The only way I can think of right now is setting the angular velocity for Z to 0 on each physics tick but I didn’t test that…

1 Like

Yeah @douter, thats about the only way, though people have reported issues when doing it like that (drifting). Would be cool if you could report back.

Yeah, but i don’t want to lock translation and rotation, but only translation in Z axis…


Originally by @normen:
you can only lock the rotation completely.

It means you can't lock only one axis, but x, y and z.

So i can’t lock Z axis completely? :<

Did you try if what douter said works for you?

Yeah, but my problem is: rotating. My object is rotating along Z axis…



Edit:

Ah, i did something wrongly. I’ll test something…



Edit2:

Not works :<

[java] Vector3f omg = orbPhys.getAngularVelocity();

omg.z = 0;

orbPhys.setAngularVelocity(omg);[/java]

In simpleUpdate()… Maybe i’m doing something wrongly again? :stuck_out_tongue:



My object (ball) is rotating and moving, but O-M-G-very-slooow…

Does this work?



[java]import com.jme3.bullet.PhysicsSpace;

import com.jme3.bullet.PhysicsTickListener;

import com.jme3.bullet.control.RigidBodyControl;

import com.jme3.math.Vector3f;



public class ZLockControl extends RigidBodyControl implements PhysicsTickListener {



public ZLockControl(float mass) {

super(mass);

}



@Override

public void setPhysicsSpace(PhysicsSpace space) {

super.setPhysicsSpace(space);

space.addTickListener(this);

}



@Override

public void prePhysicsTick(PhysicsSpace space, float f) {

setAngularVelocity(Vector3f.ZERO);

}



@Override

public void physicsTick(PhysicsSpace space, float f) {



}



}[/java]

1 Like

Looks good. For good measure you should remove the listener before calling super.setPhysicsSpace() if space == null

1 Like

No, the object is moving slowly again…

lag?

No, the object is moving slowly again…

Hm, try doing it post physics tick too..

As far as I understand you want to constrain the object from moving in the z direction, so why people are mentioning rotation I don’t understand. Edit: Since you’re mentioning axis, although later you mention moving in x and y direction.

[java]

import com.jme3.bullet.PhysicsSpace;

import com.jme3.bullet.PhysicsTickListener;

import com.jme3.bullet.control.RigidBodyControl;

import com.jme3.math.Vector3f;



public class ZLockControl extends RigidBodyControl implements PhysicsTickListener {

Vector3f linearVelocityVector;

public ZLockControl(float mass) {

super(mass);

}



@Override

public void setPhysicsSpace(PhysicsSpace space) {

super.setPhysicsSpace(space);

space.addTickListener(this);

}



@Override

public void prePhysicsTick(PhysicsSpace space, float f) {

linearVelocityVector = getLinearVelocity();

linearVelocityVector.z = 0;

setLinearVelocity(linearVelocityVector);

}



@Override

public void physicsTick(PhysicsSpace space, float f) {



}



}

[/java]

1 Like

I guessed he wanted 2d physics which mostly means no rotation around the x axis… What you do there is bad voodoo btw, do not get().set() at any time in jme3!

1 Like