I was using the built in Character Controller as well as Brackey's third person character controller, but I made it so that instead of gravity being constrained to only the y-axis, I made it a vector that can be turned to any direction. The main problem I'm having is that when my character is on a platform that isn't directly facing the normal direction and gravity is facing that exact same direction as that platform, the character seems to just slide off the platform. This happens any time gravity isn't facing either directly down or directly up, or 90 degrees left or right. If it isn't anything that isn't fully left or right or up or down (like 30 degrees for example), the character starts sliding. Could this be an issue with the Slope Limit or step offset? What could be the cause of this? Should I use of rigidbody instead if there is no solution?
#I'm having problems implementing faux gravity in which I can switching gravity to any direction
1 messages · Page 1 of 1 (latest)
public GameObject targetObject;
public float gravityStrength = 9.81f;
private Vector3 velocity;
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
Vector3 gravityDirection = -targetObject.transform.up;
// Simulate gravity
velocity += gravityDirection.normalized * gravityStrength * Time.deltaTime;
// Move the character controller using the velocity vector
controller.Move(velocity * Time.deltaTime);
}```
So you want your character to stop moving if they are grounded to the platform at all times?
Yeah. I was wondering what was causing the character to slide off the platform. I'll implement controls for the character to move around (similar to Super Mario Galaxy) but its a bit strange how the character controller moves off the platform automatically when on a certain angle (even though the character doesn't slip off at all when gravity is 0, 90, or 180 degrees).