- Home /
Transforming a single axis.
Hi.
I'm currently making an fps in which the gravity can be switched, allowing the player to walk on walls, ceiling, etc. This works fine except for one thing:
I'm using Physics.gravity to change the gravity vector, but I also need to flip the player so that their "feet" are pointing down with the gravity.
Currently, I'm using this in update:
Physics.gravity = Vector3.Slerp(Physics.gravity, targetGravity, 0.15f);
transform.up = -Physics.gravity;
Which does the job of rotating the player with gravity, but it also basically locks all rotation on the transform, so the player can't turn left or right.
Suggestions appreciated, thanks.
Answer by tMahon · May 01, 2017 at 11:09 PM
transform.up = -Physics.gravity; is locking the transform.up to the inverse of gravity, instead set it to the local transform you ideally want it to be at.
transform.up = isFacingUp ? transform.position.y + 1, transform.position.y - 1;
Your answer
![](https://koobas.hobune.stream/wayback/20220612120934im_/https://answers.unity.com/themes/thub/images/avi.jpg)