- Home /
2D Platformer Switching to horizontal gravity C#
I'm making a 2d platformer that involved switching between gravity using gravity scale and making it negative when I want the gravity to be reversed. However, throughout the game I want to change the gravity overall to the horizontal axis. Making the normal gravity be to the left and reversed to the right. I have seen a couple of topic on horizontal gravity where people have made their own gravity mechanic but nothing really worked for me.
Right now I have this:
void Start () {
playerRigidbody = GetComponent<Rigidbody2D>();
customGravity = GetComponent<ConstantForce2D>();
}
if (Input.GetKeyDown("f"))
{
customGravity.force = new Vector2(-.005f, 0);
Physics2D.gravity = new Vector2(0, 0); //testing something here
}
This way kinda works but the character keeps bumping into the walls horizontally. Also I am not sure if this would effect my jumping mechanic like gravity should.
Your answer
Follow this Question
Related Questions
2D platformer squashed 1 Answer
HOLD JUMP BUTTON TO JUMP HIGHER 2 Answers
Help !!! i'm stuck 1 Answer
How do I make it so that a gameobject can not be moved by the player? 2 Answers
How do you make a one-way slope? 0 Answers