I am creating my own
CharacterController class for a 3D environment in three.js. I am attempting to calculate my own collision detection but am running into a strange bug that I cannot put my finger on. Because in my use case the only other objects in the scene are cubes, I am using a simple rectangle hit test using each cube’s
z in comparison with the
z of my character to determine if a collision has occurred.
I am then determining the direction of the collision using some simple vector math (applying some conditionals to a direction vector calculated by comparing the difference between the center of the collided object and the center of my character).
Next I am using that direction data to limit my character’s movement in the direction of the wall. Collisions are detected correctly in all cases however movement is only limited when my character’s/camera’s direction (rotation) is perpendicular to the faces of the cubes that are parallel to the x-axis. And vice versa, when my character’s direction is facing parallel to the cubes faces that are parallel to the z-axis.
All of this code is occurring inside of my
update() function. Once the character is instantiated the
update() function runs in a three.js continuous
The code for my CharacterController class is here.