Hello, the current issue I am having is that my player floats when moving off a ramp (a mountain). So i tried to do setGravity but I dont see any change. I am using a bettercharacter control.
Code for the player physics:
[java]
playerModel = assetManager.loadModel(“Models/Player/Mage/mage.j3o”);
playerModel.setMaterial(assetManager.loadMaterial(“Models/Player/Mage/mageMaterial.j3m”));
playerModel.setLocalScale(10, 10, 10);//for mage
playerModel.rotate(0, 3.2f, 0);
player = new Player(playerModel, this.app.getInputManager(), this.app.getCamera(), this, assetManager, bulletAppState);
player.setShadowMode(ShadowMode.Cast);
player.setMage(true);
player.getCharacterControl().warp(new Vector3f(300, 2f, 320f));//this is where the player spawns
player.getCharacterControl().setGravity(new Vector3f(0f,-600f,0f));
this.app.getRootNode().attachChild(player);
this.bulletAppState.getPhysicsSpace().add(player.getCharacterControl());
this.bulletAppState.getPhysicsSpace().add(player);
this.bulletAppState.getPhysicsSpace().add(player.hitBox());
[/java]
How my player moves:
[java]
/**
* This allows the player to move.
*/
Vector3f camDir = cam.getDirection().clone();
camDir.y = 0;
Vector3f camLeft = cam.getLeft().clone();
camLeft.y = 0;
walkDirection.set(0, 0, 0);
if (left) {
walkDirection.addLocal(camLeft);
}
if (right) {
walkDirection.addLocal(camLeft.negate());
}
if (up) {
walkDirection.addLocal(camDir);
}
if (down) {
walkDirection.addLocal(camDir.negate());
}
characterControl.setWalkDirection(walkDirection.normalize().multLocal(movementSpeed));
[/java]
I want my player to have a gravity, because hes moving kinda fast sometimes he floats and if he hits ramps he goes flying. What factors are affecting my setGravity or am I doing it wrong?
This has been a known bug with the character controls with no clear solution…
Unfortunately you’re likely on your own to come up with a hacky fix such as casting a ray straight down all the time, and maybe mixing that with the isOnGround() method
The real prolbem here is, that a player has legs, wich are way more complex than a normal sphere, (eg no friction high friction based on movement, oriented friction when running downhill ecvt.) Basically you will need to adjust your player always.
What worked for me was to use a raycast and tape the player to the terrain, except if he presses jump.
Perhaps radius is not really radius… because that bounding box looks wrong then… but I read that as a character that is 3 meters wide, 5 meters tall, and yet weighs less than a small house cat.
I guess for a physics engine, these scales are not really arbitrary. And certainly if one scales up dimensions then they should scale up mass by a cube of the scaling. Double size is 8 times mass, etc…
I don’t know if it will help. I’ve never used BetterCharacterControl or Bullet… but from a physics engine I expect these things to normally matter.
@pspeed said:
Perhaps radius is not really radius... because that bounding box looks wrong then... but I read that as a character that is 3 meters wide, 5 meters tall, and yet weighs less than a small house cat.
I guess for a physics engine, these scales are not really arbitrary. And certainly if one scales up dimensions then they should scale up mass by a cube of the scaling. Double size is 8 times mass, etc…
I don’t know if it will help. I’ve never used BetterCharacterControl or Bullet… but from a physics engine I expect these things to normally matter.
Im going to play around with the values a bit more.
The third value in the BetterCharacterControl is mass according to the docs, I set it to a high a value and it does not affect my character at all. I also tried setting it to a negative value but i just fall throught the floor. Im going to have to look at all options but this floating thing is frustrating me.
First of all the gravity you set will be replaced with the gravity of the physics space when you add it. Set it afterwards or better, don’t set it at all. As pspeed said, you have a big but very light character, its five meters high but it only weighs 3 kg… So basically like a large balloon.
@normen said:
First of all the gravity you set will be replaced with the gravity of the physics space when you add it. Set it afterwards or better, don't set it at all. As pspeed said, you have a big but very light character, its five meters high but it only weighs 3 kg.. So basically like a large balloon.
Setting the gravity after adding to the physics space worked, thank you normen!
If I raise the mass, then I will have to raise all my npcs masses because colliding with them will have massive force. In addition, I tried the setGravity solution first and it worked.
I’ve solved this my setting the gravity, but the mass is set in the constructor. So I’m unsure how I would set the mass after I add an unconstructed object to the physics space.
But yes it was setting the gravity to 0, -50, 0 AFTER setting it to the physics space solved it.
>.>
That was my biggest problem for so long, probably about 5 people in the IRC about to thank me for bringing this news there
I’ve solved this my setting the gravity, but the mass is set in the constructor. So I’m unsure how I would set the mass after I add an unconstructed object to the physics space.
But yes it was setting the gravity to 0, -50, 0 AFTER setting it to the physics space solved it.
>.>
That was my biggest problem for so long, probably about 5 people in the IRC about to thank me for bringing this news there
I’ve solved this my setting the gravity, but the mass is set in the constructor. So I’m unsure how I would set the mass after I add an unconstructed object to the physics space.
But yes it was setting the gravity to 0, -50, 0 AFTER setting it to the physics space solved it.
>.>
That was my biggest problem for so long, probably about 5 people in the IRC about to thank me for bringing this news there
You don’t have to set the mass after you add it to the physics space, you can do it in the constructor.