I making a game where players can alter their direction of gravity, allowing them to walk on walls and such. Currently the players’ movement is altered using translate because that can apply movement based of the transform’s local position. The problem here is that translate can force players through level geometry and I was hoping to utilise the rigidbody for movement to fix the problem, but this seems to apply to the character in worldspace, despite using TransformDirection, which means when the players walk on the roof, their input is reversed. Does anyone know of a good way to solve this problem?
EDIT:
This here is the relevant snippets of code, I haven’t provide the whole script because it’s about 200 lines and handles many things related to the player, but not specifically to the movement
void Update() {
moveVector = new Vector3(playerInst.currState.ThumbSticks.Left.X, 0, playerInst.currState.ThumbSticks.Left.Y);
moveVector *= moveSpeed;
moveVector *= Time.deltaTime;
rotateVector = new Vector3(0,playerInst.currState.ThumbSticks.Right.X, 0);
rotateVector *= rotateSpeed;
rotateVector *= Time.deltaTime;
}
void FixedUpdate() {
rigidbody.AddForce(-gravity * rigidbody.mass * myNormal);
myNormal = Vector3.Lerp(myNormal, surfaceNormal, lerpSpeed * Time.deltaTime);
var myForward = Vector3.Cross(transform.right, myNormal);
var targetRotation = Quaternion.LookRotation(myForward, myNormal);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, lerpSpeed);
transform.Rotate(rotateVector);
transform.Translate(moveVector);
}