C
C#2y ago
pogrammerX

❔ BulletSharp FPS Controller

can someone help me with my FPS controller in my game engine, im using bullet sharp this is my code:
System.Numerics.Vector3 GetHorizontalDirection(System.Numerics.Vector3 cameraForward)
{
return new SVector3(cameraForward.X, 0, cameraForward.Z);
}

float speed = 1f;
float x = 0f;
float z = 0f;

if (Keyboard.IsKeyDown(Key.W)) z = 1f;
if (Keyboard.IsKeyDown(Key.S)) z = -1f;
if (Keyboard.IsKeyDown(Key.A)) x = -1f;
if (Keyboard.IsKeyDown(Key.D)) x = 1f;

var move = GetHorizontalDirection(Player.CameraForward) * z + Player.CameraRight * x;

if (Keyboard.IsKeyDown(Key.Space) && IsGrounded())
{
if (Player.playerBody != null) Player.playerBody.LinearVelocity = new SVector3(move.X * speed, Player.JumpVelocity, move.Z * speed);
ThreadPool.QueueUserWorkItem(UpdateSoundEnginePlayerParams, null, false);
}
else if (Player.playerBody != null)
{
Player.playerBody.LinearVelocity = new SVector3(move.X * speed, Player.playerBody.LinearVelocity.Y, move.Z * speed);
ThreadPool.QueueUserWorkItem(UpdateSoundEnginePlayerParams, null, false);
}
System.Numerics.Vector3 GetHorizontalDirection(System.Numerics.Vector3 cameraForward)
{
return new SVector3(cameraForward.X, 0, cameraForward.Z);
}

float speed = 1f;
float x = 0f;
float z = 0f;

if (Keyboard.IsKeyDown(Key.W)) z = 1f;
if (Keyboard.IsKeyDown(Key.S)) z = -1f;
if (Keyboard.IsKeyDown(Key.A)) x = -1f;
if (Keyboard.IsKeyDown(Key.D)) x = 1f;

var move = GetHorizontalDirection(Player.CameraForward) * z + Player.CameraRight * x;

if (Keyboard.IsKeyDown(Key.Space) && IsGrounded())
{
if (Player.playerBody != null) Player.playerBody.LinearVelocity = new SVector3(move.X * speed, Player.JumpVelocity, move.Z * speed);
ThreadPool.QueueUserWorkItem(UpdateSoundEnginePlayerParams, null, false);
}
else if (Player.playerBody != null)
{
Player.playerBody.LinearVelocity = new SVector3(move.X * speed, Player.playerBody.LinearVelocity.Y, move.Z * speed);
ThreadPool.QueueUserWorkItem(UpdateSoundEnginePlayerParams, null, false);
}
Player.playerBody is the RigidBody of the player. the issue is that when i walk straight i walk like forward left
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.