@normen said: What you do there is bad voodoo btw, do not get().set() at any time in jme3!: I’ve heard so, but why? It usually works. edit: Could it be because the set method might include more operations than simply setting a variable? edit2: Changed the code
I believe the platform game Trine has this kind of physics; where movement in the z-direction is constrained.
Could it be because the set method might include more operations than simply setting a variable?
Yes, and even if there are none now there might be in the future, especially in physics (native bullet).
if you don’t want movement in z-direction, then you can do:
[java]getPhysicsLocation().multLocal(1,1,0)[/java]
this makes all z values 0. And put it inside an update(float tpf); in a control for example.
-.- what did I just say? xD Also, just setting the location might cause funny physics effects, you micro-beam the object basically…
what did I just say?Haha :p
Also, just setting the location might cause funny physics effects, you micro-beam the object basically..Yeah, that's also the reason I didn't suggest that.
getPhysicsLocation().multLocal(1,1,0)Why do multiplication when you can just set the value to 0?I'ld still go with:
[java]
@Override
public void prePhysicsTick(PhysicsSpace space, float f) {
Vector3f linearVelocityVector = getLinearVelocity();
linearVelocityVector.z = 0;
setLinearVelocity(linearVelocityVector);
}
[/java]
Not works Object moves in jumps… O_o
// Edit:
O-M-G
Sorry, but m4tx is an idiot… -.-
[java] orbPhys = new RigidBodyControlZLock(1.5f);
orbPhys.setSpatial(orb);[/java]
I had this:
[java]orbPhys.setSpatial(orb);[/java]
Instead of:
[java]orbPhys.setCollisionShape(orbShape);[/java]
Eh… -.-
Now it works properly. Almost. Object is sometimes rotating around Z axis.
Use:
[java]
@Override
public void prePhysicsTick(PhysicsSpace space, float f){
Vector3f linearVelocityVector = getLinearVelocity();
Vector3f angularVelocityVector = getAngularVelocity();
linearVelocityVector.z = 0;
angularVelocityVector.x = 0;
angularVelocityVector.y = 0;
setLinearVelocity(linearVelocityVector);
setAngularVelocity(angularVelocityVector);
}
[/java]
or:
[java]
@Override
public void prePhysicsTick(PhysicsSpace space, float f){
Vector3f linearVelocityVector = getLinearVelocity();
Vector3f angularVelocityVector = getAngularVelocity();
linearVelocityVector.z = 0;
angularVelocityVector.z = 0;
setLinearVelocity(linearVelocityVector);
setAngularVelocity(angularVelocityVector);
}
[/java]
I use this first and it works :> Thanks for all!
I use this first and it works :> Thanks for all!Glad to hear it finally worked out.