I'm attempting to create an FPS using a capsule as player collision, but I'm getting a lot of erratic behavior. The player bounces up and down as he moves across the gameworld and slides up walls as I press against them. Since I migrated from XNA 3.1 to 4, the player has also begun to fall out of the world a lot as well.
The player is represented by a capsule. The settings are as follows:
Code: Select all
collisionCyl = new Capsule(position + new Vector3(0, 1, 0), 0.75f, 0.5f,5.0f);
collisionCyl.IsAlwaysActive = true;
collisionCyl.Bounciness = 0;
I'm getting the horizontal movement value from the left thumbstick of the gamepad and applying it directly as velocity like so:
Code: Select all
public void updateInput(GamePadState gps, GameTime elapsed)
{
float deltaT = (float)elapsed.ElapsedGameTime.TotalMilliseconds;
oldGPS = newGPS;
newGPS = gps;
pitch += newGPS.ThumbSticks.Right.Y * deltaT * rotSpeed;
yaw -= newGPS.ThumbSticks.Right.X * deltaT * rotSpeed;
pitch = MathHelper.Clamp(pitch, MathHelper.ToRadians(pitchMin), MathHelper.ToRadians(pitchMax));
moveRaw = Vector3.Zero;
moveRaw.Z = newGPS.ThumbSticks.Left.Y * deltaT * speed;
moveRaw.X = -newGPS.ThumbSticks.Left.X * deltaT * speed;
Matrix cameraMoveRotationMatrix = Matrix.CreateRotationY(yaw);
//NEED TO ACCOUNT FOR GRAVITY HERE
Vector3 tempVec = Vector3.Transform(moveRaw, cameraMoveRotationMatrix);
collisionCyl.LinearVelocity = new Vector3(tempVec.X,collisionCyl.LinearVelocity.Y,tempVec.Z);
}
The game world is comprised of tiles. For the time being, each of these tiles has a floor and ceiling, so I'm just adding boxes to represent those. I'm also attempting to add a triangleMeshGroup for each of the wall models for each tile.
Code: Select all
foreach (ShipTile3d st3d in testShip.tiles3d)
{
foreach (KeyValuePair<tileWallLocation, ShipTileWall> stw in st3d.tileTile.walls)
{
//ASSUMING FLOOR AND CEILING FOR NOW
testShip.interiorSpace.Add(new Box(st3d.tileEntity.WorldTransform.Translation+new Vector3(0,0.5f,0), 6, 1, 6));
testShip.interiorSpace.Add(new Box(st3d.tileEntity.WorldTransform.Translation + new Vector3(0, 5, 0), 6, 1, 6));
if ((wallModels.ContainsKey(stw.Value.type)) && (tileWallOffsets.ContainsKey(stw.Key)) && (tileWallRotations.ContainsKey(stw.Key)))
{
StaticTriangleGroup.GetVerticesAndIndicesFromModel(wallModels[stw.Value.type], out verts, out indices);
triangleMesh = new TriangleMesh(verts, indices);
triangleGroup = new StaticTriangleGroup(triangleMesh);
triangleGroup.WorldMatrix = Matrix.CreateRotationY(MathHelper.ToRadians(tileWallRotations[stw.Key])) * st3d.tileEntity.WorldTransform;
testShip.interiorSpace.Add(triangleGroup);
}
}
}
So this is where I'm at. I was thinking of digging up the CharacterController example again, but I don't know where it is and whether or not it will be applicable to the 1st person thing I'm doing. Does anyone have advice for where to look from here? I don't even need full realized solutions as much as a general area to start poking around.
Thanks in advance to anyone that has read this far.