#Odd movement bug

1 messages · Page 1 of 1 (latest)

golden goblet
#

Hi, I just released my new game and i have a couple people commenting about an odd bug in the movement controls. When the camera is facing in its initial orientation, the WASD controls work just fine, but when they move the camera, it's as is the orientation remains fixed; when facing backwards W moves backwards, and S forwards. When facing 90 degrees, A moves forward, etc.

I found this very odd because I playtested the very version they were playing, even on a secondary device. My movement script works as follows: Record WASD input into a vector3 (x = AD movement, y = 0, z = WS movement, vector is normalized. Then, multiply by some constants and apply that as a relative force to the player rigidbody, using rb.AddRelativeForce(...). The rigidbody is locked in all rotations, and the rotation is scripted to copy the horizontal rotation given by the mouse controls. I tested this, and indeed, the rigidbody object has angle 0 for x and z, and the angle of the camera for y.

What could be happening?

spare wind
#

You'd have to show the code, but this is very typical when reading individual axes directly from Euler angles (if that's what it's doing.) You can't rely on the camera's Y axis to point the same way when copied to another rotation

golden goblet
#

I can't know for sure if this works, but i've made some changes that at least didn't change the regular behaviour on my device.

Instead, of applying the rigidbody force directly in its coordinate system, i used Camera.main.transform.TransformVector(wasdInput) to transform the "intended movement direction" to global coordinates. After removing y axis and normalizing (walking movement is planar), i then apply non-locally to rigidbody (rb.AddForce(...))