Hello everyone. I’m working on a script that will allow the player to stick to a patch on the wall by changing the gravity for the patch. However, once the player is on the patch, my Vertical movement stops working properly. Horizontal still works fine, but I can’t move up the wall and when I try to move down the wall, after a small amount of input time, I fall off to the floor.
I’m assuming this has something to do with having changed the orientation of gravity, but if so I don’t know why. Can anybody lend me a hand?
private Vector3 newGravity = new Vector3(0f, 0f, 9.81f);
private Vector3 oldGravity = new Vector3(0f, -9.81f, 0f);
public float speedAdjust;
private bool canJump = false;
void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
{
Physics.gravity = newGravity;
//other.rigidbody.useGravity = false;
other.rigidbody.velocity = Vector3.zero;
PlayerController.movement = new Vector3(PlayerController.movementHorizontal, (PlayerController.movementVertical * speedAdjust), 0f);
canJump = true;
}
}
void OnTriggerExit(Collider other)
{
if(other.tag == "Player")
{
Physics.gravity = oldGravity;
//other.rigidbody.useGravity = true;
PlayerController.movement = new Vector3(PlayerController.movementHorizontal, 0f, PlayerController.movementVertical);
canJump = false;
}
}