PhysicsCharacterNode rotation

Hello :slight_smile: so…

I have an issue, on which iam working seweral days and dont know solution, i can bump my head to all walls in my house but that doesnt help :stuck_out_tongue:



Now seriously. I have spaceship, and i need to rotate it around 2 axes. Iam using PhysicsCharacterNode like i mentioned, but i saw that Normen in one topic said that PhysicsCharacterNode is not good for rotate. I choose PhysicsCharacterNode for ship because i wanted to move it, and setWalkingDirection sounded like good idea for me:) but, when i rotate PhysicsCharacterNode , ship stop moving and shes waiting for release key and then she continue flying in right way. I had solution for that, i rotated model node, and than i set walk direction from localrotation of that node, but PhysicsCharacterNode was still in same position , and i cant find any good solution to set right rotation of physical node (i need rotate it for right function of collisions).

What you would choose for moving with ship? Some better physics node in kinematic mode or smth like that ?



schema how i have it now: rootNode and physicalSpace ← player PhysicsCharacterNode ← shipPivot (which i rotate) Node ← engine Node and shipModel Node



If you cant understand this question :smiley: i can add some picture and my code.



Thanks guys :slight_smile:

Look at TestWalkingChar, you rotate the model that you attach to the Character Node.

normen said:
Look at TestWalkingChar, you rotate the model that you attach to the Character Node.

sorry to hijack
I have some concerns about rotation with character node too, um if wanted your character to thing that are not really the norm or even non rotation stuff like docking...............in my game I want my characters to get real up close and personal in fights i.e. grapple/tackle/physically struggle with each other in standing and "on the ground"...............I also wanted to have a fair bit of....um.........unconventional movement...running up walls sliding under tables, in short there will be lots of situations where characters wont be in a "standing" orientation, what would be the best way to handle the physics character situations like that.

Thanks normen for quick react. So i looked several times on that class (in past too) :confused: first thing that i dont have com.jme3.bullet.control.PhysicsCharacterControl; (weird) And second, i thought that in this example, rotation is made from camera, but i need first rotate model while moving, something like jet fighter. There will be problem too, that i maybe just dont get testclass :smiley: . Can some good soul make it clear for me? :slight_smile:





Here is my problem: picture

that picture pretty tells my concerns…I was thinking scaling the node but is that supported or even safe and scaling may mess with my combat plans…untested

If you dont have he class you dont use the latest nightly, but you have the class that is compatible o alpha-3 whenyou create a new jme3tests project.

Okey, i will better look at that class, but, its that my case ? I mean, for that spaceship with movement on that picture its ok to use walkingdirection with PhysicalCharacterNode ? Because in that example. direction of movement is directed by camera, but in my case, my character doesnt depend on camera, but camera on character. If ship want to right, she must rotate around z axis without changing movment direction, and than around X to change direction because of engine trust. Like fighter.Oto in test example move because of camera, it looks completly different to me.

setWalkingDirection is the only valid way to move the character.

Hello!



Two different things entirely wlsek. When you work with PhysicsCharacterNode you have to think of the physics object and the player model as two different things. Now, I’m not saying they’re not part of one another, because in most situations they are indeed bound together in some way/attached. What I’m saying is that the Physics node is the invisible/code representation of the player and the model is the visual representation of the player; what the player sees. You don’t need to rotate the PhysicsCharacterNode to achieve what you’re trying to do. You actually need to rotate the model and whenever the ship moves, you would need to setWalkingDirection in the direction it is pointing, normalized, multiplied by the speed you want it to go.



So you have the ship, it’s rotated all around by the player and now you want it to move forward in space. So you would grab the rotation of the model, get it as a vector, normalize that, and then multiply it by the speed you want the ship to move at and do yourPhysicsCharNode.setWalkingDirection(thatVector);



You’ll probably end up with the keys that rotate the ship, rotate only the model, and the keys that correspond to thrust triggering setWalkingDirection. Though, note that setWalkingDirection applies every frame, so you’ll need some sort of dampening unless you’re really simulating space thrust. In which case I guess you won’t be needing dampening at all XD



~FlaH

Thanks a lot for react, that was what i was thinking and iam rotating model node, not physical node, but what i need to know is, how set physicalnode right rotation :slight_smile: i will put some code how i have it for now.



Here is definition of nodes and so on (i have shipPivot like rotation node, because i want to separate ship hull and engine.

[java]



CapsuleCollisionShape shapehrace = new CapsuleCollisionShape(1,2.5f, 2);

shapehrace.setScale(new Vector3f(1.5f,0.5f,1));



playerShip = new Ship(100,20,350,1,1, "PR01");



final float mass = playerShip.getMass();

maxSpeed = playerShip.getMaxSpeed();



shipModel = (Node) assetManager.loadModel(playerShip.getAdressOfModel());

shipModel.setLocalTranslation(0,-0.5f,0.5f);



shipEngine = new Node();

shipPivot = new Node();



player = new PhysicsCharacterNode(shapehrace, mass);

player.setGravity(0.000000000001f);

player.attachDebugShape(assetManager);

player.setLocalTranslation(new Vector3f(playerShip.getX(),playerShip.getY(),playerShip.getZ()));



playerCamera = new CameraNode("Player cam", cam);

playerCamera.setControlDir(ControlDirection.SpatialToCamera);

playerCamera.setLocalTranslation(0, 6, -25);



chaseCam = new ChaseCamera(cam, shipPivot, inputManager);

chaseCam.setMaxVerticalRotation(FastMath.PI);

chaseCam.setDefaultHorizontalRotation(FastMath.PI);

chaseCam.setDefaultDistance(30);



shipPivot.attachChild(shipModel);

shipPivot.attachChild(shipEngine);

player.attachChild(shipPivot);

player.attachChild(playerCamera);



getPhysicsSpace().setGravity(Vector3f.ZERO);

getPhysicsSpace().add(player);



rootNode.attachChild(player);

[/java]



and here is my rotation and walkdirection setings (simple update method):



[java]

if(right){

shipPivot.rotate(pitch1a);







}

if(left){

shipPivot.rotate(pitch1a.inverse());





}

if(up){



shipPivot.rotate(pitch2a);





}

if(down){

shipPivot.rotate(pitch2a.inverse());









}

if(slows){

if(actualSpeed <= 0) actualSpeed =0;

if(actualSpeed > 0) actualSpeed -=0.1;

}

if(steers){

if(actualSpeed < maxSpeed) actualSpeed +=0.1;

}

if(rlm){

playerCamera.setEnabled(false);

}else{

playerCamera.setEnabled(true);

playerCamera.lookAt(player.getLocalTranslation(),new Vector3f(1,0,0));

}



shipPivot.getLocalRotation().getRotationColumn(2,walkDirection);

walkDirection.multLocal(actualSpeed);

player.setWalkDirection(walkDirection);



[/java]





But thats not right solution, because how you can see on picture, PhysicalCharacterlNode player doesnt rotate, collision shape remains same.

Hello again,



There’s only two options I see, maybe someone else has some insight too.



If you don’t need perfect collision results, why not make the ship have a sphere collision shape, a box, or just something more generalized? Most games don’t use perfect collision bounds, but I don’t know your specific application.



Maybe PhysicsCharacterNode isn’t the solution and you need to make it a PhysicsNode? This is where my knowledge abruptly hits a hurdle as I’m still learning a lot about how to work with the physics.



Long and the short is, if you absolutely need to use an oblong shape that requires rotation and can’t get by with something more generalized like a sphere, then PhysicsCharacterNode is probably not what you want to use. The whole point of the physicsCharacterNode is to have an upright/walking character with axis locks.



EDIT: And yeah, I don’t see anything wrong with the way you’re doing it. That’s about how I’d do it.



~FlaH