Creating simple physics

I can see that jME-Physics 2 has very good physics simultaions, but what if that is not what I want? I just want to set the material of my object to a simple material that will move one direction while the key is down and then stop when he lets go. I also don't want the object to roll or flip over. How do i do this?



Jedimace1

Just use animations / change the translation of the object to move it?

Then the collision detection won't work, and i still want to be able to do stuff like jumping, not being able to walk through walls, falling, and switching the gravity. I simply don't want it to roll or fall over, and I don't want it to slide after you let go.

You can use the collision detection without the physics simulation. But it's not easy to turn off parts of the simulation (like gravity without rolling). So your best bet is probably to simulate/animate everything yourself and use the physics collision detection for input to your simulation.

Ah you are working with the same problem Jedimace1. Maybe we can achieve a more satisfying result in here  :slight_smile:

Since I have the same problems - at least as long as I consider having a playerobject as a dynamic physicsnode - let's see what we can do:



I cobbled together some code from the physics tutorials and some code I found in some forum posts to achieve whats needed. The result still not satisfying enough, but at least "box always upright" / "stop when releasing button" works. When you are on a ledge/fall down a hole or jump you won't roll over and gravity works well.



However when u try 'walking' along the blue wall in the following sample code sometimes when rotating the box it gets an evil spin around and bounces away. Also sliding down on objects (the green wall) with an angle of 15

Ok, I tried it and identified the problem. It doesn't like the set surface motion thing you are doing when you hit the wall. After we fix that, i think it is pretty good, BUT, what about going up slopes? I think I could just take off the rotation part when I use it in my game, because I think it will look good. But after we get the side movement working, this will be good. Also, beware, I am using jME 2.

Jedimace1 said:

Ok, I tried it and identified the problem. It doesn't like the set surface motion thing you are doing when you hit the wall. After we fix that, i think it is pretty good, BUT, what about going up slopes? I think I could just take off the rotation part when I use it in my game, because I think it will look good. But after we get the side movement working, this will be good. Also, beware, I am using jME 2.


Ah I have tried it out myself just while you were asking about slopes(I've edited the code above and put in a green "slope"). The playerobjects slides down however. The best would be of course an angle to determine if the player can walk up or not. Don't know how to achieve this. Hmmm if the surface motion of the wall is the problem for bouncing back, maybe I can separate floor and wall....

public void setSurfaceMotion(Vector3f motion)

Surface motion - if set, the surface is assumed to be moving independently of the motion of the nodes. This is kind of like a conveyor belt running over the surface.

Parameters:

motion - this vector specifies the motion of the surface in geometry coordinate space. This results in a motion relative to the world rotation of the geometry but independent from the direction of the surface itself.

player.rotateUpTo(new Vector3f(0,1,0));


Commenting out this line fixes it, so it will work with rotation, but the wall is still messed up.
Jedimace1 said:

public void setSurfaceMotion(Vector3f motion)
Surface motion - if set, the surface is assumed to be moving independently of the motion of the nodes. This is kind of like a conveyor belt running over the surface.
Parameters:
motion - this vector specifies the motion of the surface in geometry coordinate space. This results in a motion relative to the world rotation of the geometry but independent from the direction of the surface itself.

I don't think using this function is what we want, is it? It is changing the material, not actually moving it, so it is trying to, I guess, conveyor belt into the wall. SO, when It collides, it receives pushing on the side to(the material is also pushing up), flinging the object away. That also explains why it works on the top. I hope you can understand what I am saying, not very good at explaining.

I guess I realize what you mean. Obviously this whole approach with SurfaceMotion seems somehow wrong now scratching head

And that's why I posted this… I have no clue how to do this. I am out for now, so good luck.

I started from Lesson1 once again not using any SurfaceMotion, but it still doesn't work well… either the box rotates somehow on a slope, or it slides down the slope (which is logical however, because the box is upright as a human should be but only stands on 1 edge…) - also my code is ugly.

I guess using a FPS playerobject as a physicsBox is very tricky… and probably not worth the effort if you consider all the problems and that it's not usable very good in multiplayer.



It's still possible to use physics-objects being influenced by a nonphysical playerobject. A friend of mine told me how to aproach it: whenever the player collides with an object (e.g. a chair) you could make the player "push" the object with 2 constant forces (either walk or run) and implement it simply by adding the appropriate force to the object when the player collides with it. This seems to take place in Deus Ex 2 if I remember correctly: chairs/tables, bottles etc. get pushed away simply by colliding with them…

Though you still need to implement some kind of physics for the 2 actions: jumping & falling down :expressionless:



If just anyone could tell, if the approach "playerobject as physics-object" is WRONG or RIGHT, since I read some posts claiming: "it is the wrong way" or "even commercial games do not use the playerobject as a physicsobject"… but why then dozens of people still try to implement it as a physicsobject?



(Another thing: why the hell can't I find the JMEPhysics API on the websites. Where is the damn javadoc??? I can only guess functions and material-variables :x)


import java.util.logging.Level;
import java.util.logging.Logger;

import com.jme.input.InputHandler;
import com.jme.input.KeyInput;
import com.jme.input.action.InputAction;
import com.jme.input.action.InputActionEvent;
import com.jme.input.util.SyntheticButton;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.PhysicsSpace;
import com.jmex.physics.PhysicsUpdateCallback;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.callback.FrictionCallback;
import com.jmex.physics.contact.ContactInfo;
import com.jmex.physics.contact.MutableContactInfo;
import com.jmex.physics.geometry.PhysicsBox;
import com.jmex.physics.material.Material;
import com.jmex.physics.util.SimplePhysicsGame;

public class Lesson1 extends SimplePhysicsGame {
   
   DynamicPhysicsNode dynamicNode;
   boolean onFloor = false;
   
    protected void simpleInitGame() {
        final StaticPhysicsNode staticNode = getPhysicsSpace().createStaticNode();
        rootNode.attachChild( staticNode );

        // now we create a collision geometry for the floor - a box
        Box floorBox = new Box( "floor",new Vector3f(), 40, 0.5f,10 );
        staticNode.attachChild(floorBox);
       
        final Box slope = new Box("slope", new Vector3f(), 4, 0.5f,10);
        slope.getLocalTranslation().set( 20,0,0 );
        slope.getLocalRotation().fromAngleAxis(30*FastMath.DEG_TO_RAD, new Vector3f(0,0,1));
        staticNode.attachChild( slope );
       
        staticNode.generatePhysicsGeometry();

        // man muss f

owaye said:

(Another thing: why the hell can't I find the JMEPhysics API on the websites. Where is the damn javadoc??? I can only guess functions and material-variables :x)

Just use a proper IDE(-configuration). It shows the JavaDoc right from the sources.