Alright, so after taking a quick break from my voxel world I’ve got back to it, and it’s going pretty good so far.
Right now I’m trying to convert my code that uses CharacterControl to use the BetterCharacterControl, and the only issue I’m having so far is getting it to move a node…
Here is the code I’m using…
[java]playerNode = new Node();
player = new BetterCharacterControl(.9f, 1.9f, 1f);
player.setJumpForce(new Vector3f(0, 0, 0));
player.setGravity(new Vector3f(0, -10, 0));
playerNode.addControl(player);
app.getStateManager().getState(BulletAppState.class).getPhysicsSpace().add(player);
playerNode.setLocalTranslation(new Vector3f(2, 35, 2));[/java]
Ultimately what I’m doing with it is moving the camera based on the node’s location, however the node isn’t moving, so neither is the camera…
It’s using the BetterCharacterControl, it doesn’t have that method… (Actually it does, but it’s protected… and I would make an class that extends it, but I don’t think it was meant to be done that way, and will cause issues…)
I think hes saying that setWalkDirection() overrides warp() because they both end up calling the same internal function.
Kind of like how spatial.move() is an alias for spatial.setLocalTranslation(). You should probably try a fresh project and try your code out. I just set up the same sort of thing and didn’t have an issue.
Yeah, this behavior is weird…
I recommend testing it on a fresh project as well.
Maybe you have some code setting the node to (0,0,0) somewhere hidden…
I use BetterCharacterControl all the time and it works fine.
Also when you have a little, fresh project, you can easily send us all of the source code.
Well, I’m glad to announce to you…
…everything works
The player spawns and gets teleported to (2, 35, 2) and starts falling.
If you wanna move the node, you need to add something like
player.setWalkingDirection(new Vector3f(1,0,0);
to the simpleUpdate method.
If you wanna move the player through keys, you need to add the mapping to the input manager, calculate the appropiate walking direction and apply it.
This is an object that manages the a player
*/
public class Player
{
// Our boolean variables for movement
public boolean forward = false, backward = false, lStrafe = false, rStrafe = false;
// Temporary vectors for moving the player
private Vector3f camDir;
private Vector3f camLeft;
private Vector3f walkDir;
private Vector3f loc;
// The camera that this player can see
private Camera cam;
// The actual player object
private BetterCharacterControl player;
// The node that manages the player
private Node playerNode;
/**
This is the constructor, it is in charge of initializing default values
@param cam :: The camera that this player uses
@param Bas :: BulletAppState, used for incorporating physics
*/
public Player(Camera cam, BulletAppState Bas)
{
// Initialize vectors now to save time later
camDir = new Vector3f(0,0,0);
camLeft = new Vector3f(0,0,0);
walkDir = new Vector3f(0,0,0);
loc = new Vector3f(0,0,0);
// Store the given camera
this.cam = cam;
// Setup global character properties
player = new BetterCharacterControl(.9f, 1.9f, 1f);
player.setJumpForce(new Vector3f(0, 0, 0));
player.setGravity(new Vector3f(0, -10, 0));
// Attach the player and give it physics
playerNode = new Node("Player Node");
playerNode.addControl(player);
Bas.getPhysicsSpace().add(player);
// Initialize to default location
player.warp(new Vector3f(2, 35, 2));
}
/**
This is the update sequence, it
Manages the walking behavior
@param tpf :: The time per frame
*/
public void update(float tpf)
{
// Establish camera directions
camDir.set(cam.getDirection().multLocal(0.125f));
camLeft.set(cam.getLeft().multLocal(0.08f));
// Reset walk direction, and fix a camera direction issue
camDir.y = 0;
walkDir.set(0,0,0);
// Set the walk direction
if(forward)
{walkDir.addLocal(camDir);}
if(backward)
{walkDir.addLocal(camDir.negate());}
if(lStrafe)
{walkDir.addLocal(camLeft);}
if(rStrafe)
{walkDir.addLocal(camLeft.negate());}
// Walk
player.setWalkDirection(walkDir);
// Setup the camera to match the walk direction
loc.set(playerNode.getLocalTranslation());
loc.y += 1.5;
cam.setLocation(loc);
System.out.println(playerNode.getLocalTranslation());
}
/**
Makes the player jump
*/
public void jump()
{player.jump();}
}
[/java]