© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
1 reply
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Bullet World.Step causes 0xC000001D Illegal Instruction (C BulletSharp)
C#CC# / help
4y ago
Mapping controller to / without breaking other controllers
C#CC# / help
3y ago
Auth Base Controller?
C#CC# / help
12mo ago
Character Controller Issue
C#CC# / help
2y ago