No clue what you want to tell me
in this sample:
https://jmonkeyengine.github.io/wiki/jme3/beginner/hello_physics.html
Author use RigidBodyControl(2f);
brick_phy = new RigidBodyControl(2f);
brick_geo.addControl(brick_phy);
bulletAppState.getPhysicsSpace().add(brick_phy);
next he add ball
ball_phy = new RigidBodyControl(1f);
/** Add physical ball to physics space. */
ball_geo.addControl(ball_phy);
bulletAppState.getPhysicsSpace().add(ball_phy);
/** Accelerate the physcial ball to shoot it. */
ball_phy.setLinearVelocity(cam.getDirection().mult(25));
But this is work for RigidBodyControl.
In my sample use: PlayerControl.
When capsule collision between game level and player.
And not between the players.
If i add to player RigidBodyControl how in the sample - itās not work.
Next i try add RigidBodyControl and add player to player.
Maybe use the BetterCharacterControl, maybe that control object has mode where you can say ācolideā or something like that. Just guessing, itās a while since I used that.
NOTE: in case you already tried that, just ignore me, often I missinterpret a question or just donāt read it carefully enough
Where in bettercharactercontrol method āgetPhysicsPositionā ?
Add player to player - not work.
Okay we have methods:
getCollideWithGruops()
setCollideWithGruops()
removeCollideWithGruops()
I donāt know really. I only know that ther is a better character control and I would have to check it as well, I donāt want to put away the fun for you
physics listener for bad happening
Changes the collision shape after creation.
setCollideWithGroups()
setCollisionGroup()
addCollideWithGroup(COLLISION_GROUP_01)
removeCollideWithGroup(COLLISION_GROUP_01)
Collision Groups are integer bit masks ā enums are available in the CollisionObject. All physics objects are by default in COLLISION_GROUP_01. Two objects collide when the collideWithGroups set of one contains the Collision Group of the other. Use this to improve performance by grouping objects that will never collide in different groups (the the engine saves times because it does not need to check on them).
I try this)))))
Level collide with group = 1
//capsuleShape.
characterControl = new PlayerControl(capsuleShape, 0.05f);
characterControl.addCollideWithGroup(collide_group_1);
collide_group_1 = 1
not work.
Try add rigid body control and add group = 1 to all
rigidControl = new RigidBodyControl(capsuleShape,1.5f);
rigidControl.setCollideWithGroups(collide_group_1);
rigidControl.setPhysicsLocation(startLocation);
characterModel.addControl(rigidControl);
game.bulletAppState.getPhysicsSpace().add(player.rigidControl);
Capsule drop down under level and not work.
Try physics listener
Not work listener if make with player control
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package game;
import com.jme3.bullet.collision.PhysicsCollisionEvent;
import com.jme3.bullet.collision.PhysicsCollisionListener;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
/**
*
-
@author nn
*/
public class JPlayerControl extends PlayerControl implements PhysicsCollisionListener{public JPlayerControl(CapsuleCollisionShape capsuleShape, float f) {
super(capsuleShape, f);}
public void collision(PhysicsCollisionEvent event) {
if(event != null){
if(event.getNodeA() != null){
System.out.println(āAā + event.getNodeA().getName());} } //System.out.println("A" + event.getNodeA().getName());
}
}
Make this
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package game;
import com.jme3.bullet.collision.PhysicsCollisionEvent;
import com.jme3.bullet.collision.PhysicsCollisionListener;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
/**
*
-
@author nn
*/
public class JCollisionControl extends RigidBodyControl implements PhysicsCollisionListener {public JCollisionControl(CollisionShape shape, float mass) {
super(shape, mass);
}public void collision(PhysicsCollisionEvent event) {
if(event != null){
if(event.getNodeA() != null){
System.out.println(āAā + event.getNodeA().getName());} }
}
}
and add to level - not work ((((
Concept.
1.Create mathematics cube for all players and check collisions.
2. Cube = vectors a1,a2,a3,a4,a5,a6,a7,a8.
- Get physics position. Vector pp = getPhysicsPosition(); (x y z)
- Create constants for cube points (size):left_right,up
- Create cube points
- Check collisions between cubes
Dude, are you fu*cking serious???
I mean, really? ???
READ THIS: https://jmonkeyengine.github.io/wiki/jme3/advanced/walking_character.html#bettercharactercontrol
HAVE A CLOSER LOOK AT THE SECOND CODE SNIPPET !!! BUT PLEASE READ !!!
GOOD LUCK!
DOMENIC
Domenic. how to get physics position from better character control?
or model move with the control?
he contains collisions between controls?
I make this. Player Init
controls
capsuleShape = new CapsuleCollisionShape(1.1f, 3.1f, 1);
//capsuleShape.
//characterControl = new PlayerControl(capsuleShape, 0.05f);
characterControl = new PlayerControl(capsuleShape, 0.05f);
// characterControl.getPhysicsSpace().addCollisionListener((PhysicsCollisionListener) characterControl);
characterControl.setCollideWithGroups(group_1);
characterControl.setCollisionGroup(group_1);
characterControl.setJumpSpeed(20);
characterControl.setFallSpeed(100);
characterControl.setGravity(60);
3d
//characterControl.set
//characterControl
// characterControl.setPhysicsLocation(new Vector3f( 0.9f, 0.02f, 0.22f));
characterModel = (Node) assetManager.loadModel(modelPath);
moveSpatial = characterModel.getChild("base.obj");
characterModel.move(0.050779365f, -1.74886445f, 12.0f);
characterModel.rotate(1.0f, 0.0f, 0.0f);
moveSpatial.setLocalTranslation(new Vector3f(0, -0.2f, 0));
animations
AnimListener rotateListener = new AnimListener();
AnimListener runListener = new AnimListener();
rotateControl = characterModel.getChild("base.obj").getControl(AnimControl.class);
rotateControl.addListener(rotateListener);
rotateChannel = rotateControl.createChannel();
runControl = characterModel.getChild("base.obj").getControl(AnimControl.class);
runControl.addListener(runListener);
runChannel = runControl.createChannel();
characterControl.setPhysicsLocation(startLocation);
//rotateChannel.setAnim("direct-left");
runChannel.setAnim("run");
runChannel.setSpeed(0);
runChannel.setLoopMode(LoopMode.Loop);
rotateChannel.setAnim("direct");
rotateChannel.setSpeed(0);
rotateChannel.setLoopMode(LoopMode.DontLoop);
Iād have to agree with Domenic, I personally spent a whole 5 months reading the excellent tutorials they provide before I even downloaded the SDK and attempted to code anything, because I knew Iād run into many misunderstandings that would clear up with time and persistence, and even now I still have to reference the wiki and java docs frequently. I feel as though youāre getting yourself caught up in the theory more than you need to, when it looks like you could just use some more time playing around with and learning their physics libraries.
The code in your orginal post āshouldā work if you use a BetterCharacterControl - the only 2 essential steps for proper physics collision are to 1. attach a BetterCharacterControl to a spatial, and then 2. add it to the BulletAppState.
charControl = new BetterCharacterControl(2.8f, 20.1f, 180f);
charControl.setSpatial(groundNode);
groundNode.addControl(charControl);
bulletAppState.add(charControl);
how to move model with the control?
Yesā¦ 10 yers, 5 years university, 5 years work - itās hard for brain and exhausting.
i have this code for move model:
/**
* Move and rotate model
*/
walkDirection.set(0, 0, 0);
if (Left) {
walkDirection.addLocal(camLeft.mult(speed));
}
if (Right) {
walkDirection.addLocal(camLeft.mult(speed).negate());
}
if (Up) {
walkDirection.addLocal(camDir.mult(speed));
//rotate_channel.setLoopMode(LoopMode.DontLoop);
}
if (Down) {
walkDirection.addLocal(camDir.mult(speed).negate());
}
characterControl.setWalkDirection(walkDirection.mult(speed));
float cX = characterControl.getPhysicsLocation().x;
float cY = characterControl.getPhysicsLocation().y;
float cZ = characterControl.getPhysicsLocation().z;
// System.out.println("Location.x: " + cX + " Location.y: " + cY + " Location.z: " + cZ);
float mX = characterModel.getWorldTranslation().x;
float mZ = characterModel.getWorldTranslation().z;
float mY = characterModel.getWorldTranslation().y;
float difX = cX - mX;
float difY = cY - mY;
float difZ = cZ - mZ;
//characterModel.move(difX, difY - 2, difZ + 2);
characterModel.move(difX, difY - 1.8f , difZ);
float[] angles = new float[3];
camRotation.toAngles(angles); // we get the cam angles here
angles[0] = 0; // you don't want to rotate along the x-axis, so we set it to 0
angles[2] = 0; // you don't want to rotate along the z-axis, so we set it to 0
characterModel.setLocalRotation(characterModel.getLocalRotation().fromAngles(angles));
how to extract from better control
float cX = characterControl.getPhysicsLocation().x;
float cY = characterControl.getPhysicsLocation().y;
float cZ = characterControl.getPhysicsLocation().z;
Thereās actually no method to extract the location of the physics control. You can still do this though, I usually reference my model and use node.getWorldTranslation() for this, and as long as your model is properly attached to the physics control then this will work for you.
For example?
I need coordinates or etc for send to server and syncronization